开发者

UML Interface has association with class?

I have a class (Class A) which contains objects of type Class B. Class B has three subclasses.

Should Class B actually be an interface and then I can draw an aggregation association between the interface and Class A (and the three subclasses implement the interfac开发者_开发技巧e)

or

Should Class B, be an actual Class, have 3 sub-classes and all four of the classes (Class B + 3 subclasses) implement the interface (through Class B)?


I would say to ask yourself these questions: 1. Would you ever create an instance of Class B? If yes, then it should be a regular class. If not, 2. Should class B contain any functionality that the derived classes should be able to use? If yes you should create an abstract class that the other classes inherit, if no, make it an interface.


If Class A contains objects of type Class B that means that Class B is instantiated, therefore it can't be an interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜