Eric Saboia Eric Saboia - 21 days ago 6
Java Question

Multiplicity and aggregation in abstract class

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

Example:

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

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


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

Answer

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.