Aggregation or composition or simple association?

There is one example of explaining associations in UML.

A man works for a company; The company has a number of offices.

But I cannot understand the relationship between the Person, Company, and Office classes. I understand:

  • the company consists of many people as employees, but these classes exist independently of each other, so this is a simple association with 0 .. * plurality at the end of the Person class
  • the company has many offices, and these offices will not exist if there is no company, so this is the composition in which the company is the parent class, and 0 .. * multiples at the end of the branch.

But I'm not sure about the 2nd point. Please correct me if I am wrong.

Thanks.

+1
source share
2 answers

Why use composition or aggregation in this situation? The UML specification leaves sense of aggregation for the fashion designer. What do you want this to mean for your audience? And the meaning of the composition is probably too strong for this situation. So why use it here? I recommend you use a simple association.

If I were you, I would remain true to the problem area. In a world that I know, offices cease to exist when a company goes out of business. Rather, the Company occupies a certain number of offices for a limited period of time. If a Company goes out of business, Offices are sold or leased to another company. Offices are not burned on the ground.

If you are not faithful to the problem domain in the application, then the shortcuts that you use become invalid when the client "changes the requirements" for this application. The problem area is not really changing much, just shortcuts that you are allowed to accept. If you run shortcuts to meet requirements so that they are not properly aligned with the problem domain, it is expensive to set up the application. Your client becomes unhappy, and you finish work overtime. Save yourself and everyone in trouble!

+1
source

As long as Jim answers correctly, I want to add more information. There are two main ways to use aggregation.

  • Memory management
  • Database management

In the first case, he gives a hint how long the objects will live. This is directly related to memory usage. If the target language is one that (like most modern languages) uses the garbage collector, you can simply ignore this model information.

In the second case, it is only partially a matter of memory. Compound aggregation in the database indicates that aggregated elements must be deleted along with the aggregating element. This is less memory, but in most cases a security issue. Therefore, here you need to think twice.

However, the totality has a very esoteric significance in all cases.

+1
source

Source: https://habr.com/ru/post/1245380/


All Articles