【发布时间】:2016-09-20 19:23:35
【问题描述】:
我无法确定下面这两个示例的优缺点。理想情况下,我想知道哪种设计最重要:
示例 1(类型属性):
public abstract class Animal : /* all relevant interfaces*/
{
/*
All necessary implementations
*/
}
Public class Dog : Animal
{
Public string Name {get; set;}
Public Breed Type {get; set;}
/*
All necessary implementations
*/
}
Public Type Breed
{
Bulldog,
Chihuahua,
Labrador,
/*
So on……
This can grow without limitation,
you dno't know how much it will grow into, or
what breed you will have tomorrow e.g BulldogChihuahuaCross,
or BulldogLabradorCross.
*/
}
示例 2(空派生类):
public abstract class Animal : /* all relevant interfaces*/
{
/*
All necessary implementations
*/
}
Public class Dog : Animal
{
Public string Name {get; set;}
/*
All necessary implementations
*/
}
Public class Bulldog : Dog
{
/* Empty Class */
}
Public class Chihuahua: Dog
{
/* Empty Class */
}
Public class Labrador: Dog
{
/* Empty Class */
}
编辑:
在示例 1 中,创建了 Dog 的实例并将其类型分配为属性,在示例 2 中,创建了该特定类型的实例。
我正在寻找一些深入的论点、可扩展性、可维护性、如果有 1000 种品种的 CPU 成本、运行查询的成本等。
【问题讨论】:
-
这其实是一个很好的问题,大多数人都懒得问。我有一个我认为对你来说很好的答案,但是直到今天晚些时候才有时间正确地写出来。敬请期待。
-
@JimL。期待您的回答。
-
@JimL。或者就像费马说的:我有一个很好的证明,但是这里的空白太窄了,不能写下来;-)
-
@ThomasKilian 我不会拒绝听你的意见:)。
标签: architecture uml