1

Just started with Star UML to draw a class diagram.

As with any application, MyBLL(business layer) creates an instance of Model after interacting with the DAO(database layer).

More or less, the simplified (for clarity) class diagram looks like this:

enter image description here

It is obvious that the model class will no longer be used after BLL is done.

  1. What should I use here? aggregation or composition while mapping MyBLL to MyModel.

  2. I have used a composition relationship from MyBLL to MyDAO. My logic is after the BLL layer exists, MyDAO will no longer exist because it is referenced in MyBLL. Is this correct?

Note: This is for a WebAPI project that I am creating using C#.

1 Answers1

5

Aggregate means that the child CAN exist without the parent. So, Classroom (parent) and Student (child) is the most common example. Where you can have classrooms and students independently.

Composite means that the child CANNOT exist without the parent. So, House (parent) and Room (child) is the most common example. Where you cannot have a room without it being inside a house.

Without seeing exactly how you are coding this I am guessing that you will have this:

1) MyModel is probably a composite relationship because it is contained (with other models) within your MyBLL for its whole life. When MyBLL goes out of scope so too does MyModel.

2) MyDAO is probably an aggregate because it can exist without MyBLL as it is used by other components? I.e. It is probably created outside of your MyBLL by the host and injected into your BLL?

Both of these statements may not be true based on the actual way your have architected your system.

Belogix
  • 8,129
  • 1
  • 27
  • 32
  • Clear and up to the point. Thanks. And with Point 2: `I am just referencing the DAO library, creating and using it within the BLL`. So, accordingly BLL to DAO should be composite right (with reference to my case` ? – now he who must not be named. Jul 21 '14 at 13:56
  • 1
    In that case then yes they are both composite because the BLL is creating everything and without it nothing can exist. Whether that is what you actually want is another matter but at least it will be clear to see that BLL is owner / container of everything. – Belogix Jul 21 '14 at 13:58
  • http://www.uml-diagrams.org/association.html#composition says "..When composition is used in domain models, both whole/part relationship as well as event of composite "deletion" should be interpreted figuratively, not necessarily as physical containment and/or termination.." – xmojmr Jul 22 '14 at 05:31