Search code examples
c#design-patternsclass-diagram

Class Diagram if the relationships are correct


I created a Class Diagram. This is just a concept but i want to know if the relationship are correct and if i fully understand it.

MainClass

  • CreateClassA(); creates ClassA with new ClassA();
  • CreateClassB(); creates ClassB with new ClassB();
  • getConcreteFromCreator(); get the concrete class from creator. The creator has a switch case to determine which concrete class to return.
    • After the class is returned then call it for example (Abstract callConcrete = new ConreateA())
  • CreateClassAA(); creates ClassAA with Interface createClassAA = new ClassAA();

ClassAA

  • ClassAA creates classBB with new ClassBB();

Relationship from ClassAA to ClassBB is this suppose to be a composition? since the classAA is the creator of ClassBB and it depends on it from existing The relation between InterfaceAA and ClassAA is realization. I wasn't able to draw the line using NClass diagram.

Class Diagram


Solution

    1. Relation between ClassAA and ClassBB is composition only in case the instance of ClassBB created by ClassAA is stored inside ClassAA and not shared with external entities. In this case it would be good OO practice to hide this implementation detail and perform the necessary initialization inside the ClassAA's constructor or a dedicated Initialize method.
    2. Don't know anything about NClass, but realization is specified by a dashed line with a hollow triangle pointing to interface. Based on the screenshots on their site, it is supported.