Understanding composition in classes
When we create an application that employs numerous classes, we must decide how they will interact with each other. In object-oriented programming terminology, a method in one class that calls a method in another class is called messaging. Despite this, most developers describe this as calling a method, as I do. How objects send these messages or call methods in other objects is what composition is about.
There are two ways for objects to be connected – association and aggregation. Let’s discuss these connections.
Association
In association, the object reference we need to call or message a method is created outside the calling object. Let’s begin with a class that we will want to call:
public class Receiver { public void displayName(String name) { System.out.printf("%s%n", name); } }
This is a trivial method...