Eric Saboia Eric Saboia - 1 year ago 90
Java Question

Multiplicity and aggregation in abstract class

Can I do aggregation between an abstract class and a concret class?.


Concrete class: Enterprise
- int cod;
- String name;
- List<Office> listoffice;

Abstract class: Office
- int cod;
- String name;
- List<Enterprise> listenterprise;

Remembering, Office class will have a concrete class to instance object with inheritance later.

Answer Source

Here, I suppose that Enterprise is the owner of the aggregation relation and Office is the target of the relation.

In UML, nothing prevents you from doing an aggregation between an abstract class and a concrete class.
You should do that aggregation if conceptually, all concrete sub-classes of Office are also the targets of the aggregation of Enterprise class. You should do that because it factorizes these relations and it brings information that you don't need to repeat for each concrete Office subclass.

However, if conceptually, it exists at least one concrete subclass of Office which may not be the target of the aggregation from Enterprise, don't use the aggregation with as target the abstract class because otherwise your model would be inaccurate.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download