Association and Aggregation


Association
Association represents the relationship between the objects. Here, one object can be associated with another object or many objects. There can be four types of association between the objects:
  • One to one,
  • One to many,
  • Many to one, and
  • Many to many.
Aggregation
Aggregation is a way to achieve association. Aggregation represents the relationship where one object contains other objects as a part of its state. It represents the weak relationship between objects. It is also termed as a has-a relationship in Java. On the other hand, inheritance represents the is-a relationship. It is another way to reuse objects.

public class Person {
  String name;
  Address ad;

Composition
Composition is also a way to achieve association. There is a strong relationship between the containing object and the dependent object. It is the state where dependent objects do not have an independent existence. If you delete the parent object, all the child objects will be deleted automatically.

// School class which contains students
class School {
  private final List<Student> students;

Object-Based Programming Languages
Object-based programming languages (such as JavaScript and VBScript) follow all the features of OOPs except inheritance.

Review: Object-Oriented Programming Concepts
    Inheritance represents the is-a relationship. Which represents the has-a relationship?

      Aggregation
      Composition
      Encapsulation
      Message passing
        Result:




      Young Son: “Is it true, Dad, that in some parts of Africa    
      a man doesn’t know his wife until he marries her?”    
      Dad: “That happens in every country, son.”