Aggregation in Java

Categories: Java // Tags: , , .

// By:Team // No Comment

Email this to someonePrint this pageShare on Google+3Share on Facebook7Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon0


Aggregation in Java
If a class have an entity reference, it is known as Aggregation. Aggregation represents HAS-A relationship.

Consider a situation, Employee object contains many informations such as id, name, emailId etc. It contains one more object named address, which contains its own informations such as city, state, country, zipcode etc. as given below.

In such case, Employee has an entity reference address, so relationship is Employee HAS-A address.

Why use Aggregation?

  • Why use Aggregation?

Simple Example of Aggregation

aggregation in java

In this example, we have created the reference of Operation class in the Circle class.

Test it Now

When use Aggregation?

  • Code reuse is also best achieved by aggregation when there is no is-a relationship.
  • Inheritance should be used only if the relationship is-a is maintained throughout the lifetime of the objects involved; otherwise, aggregation is the best choice.

Understanding meaningful example of Aggregation

In this example, Employee has an object of Address, address object contains its own informations such as city, state, country etc. In such case relationship is Employee HAS-A address.

Address.java

Test it Now

Email this to someonePrint this pageShare on Google+3Share on Facebook7Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon0

About Team

Browse Archived Articles by Team

Related

Sorry. There are no related articles at this time.