Aggregation and Composition
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaX30FYZlvZe87h_EwV7swkGkSWciLA0y7_KuXRM9dmY9F3EUdEQn3pTkxsFO1VuknapuJfYNLc8xgqd3xdDrWwYMprF7AEqJdNcB0xkQDE4oumYfddlZLuMu2rAQzuRZzzXsD_0TikiU/s1600/listInterface.png)
When determining the relationship between object at design time, it is easy to succumb to the habit of using inheritance; simply because it is easy. In a language such as C++, it is even easier to do so because the language supports multiple inheritance. Figure 1 : the java.util. List Interface Assume that Java does not have a Stack (java.util.Stack) class and you need to create a custom stack (call it MyStack). You could do this in three different ways, but for the purposes of this paper I will discard the creation of the Stack class as shown in the image above. Therefore, assume that there are only two ways. The first way is to extend the ArrayList class. The second way is to include an ArrayList object as a data member. The first solution uses inheritance to solve the problem. Remember, inheritance establishes an “is-a” relationship between objects. Therefore, the relationship between MyStack and ArrayList is incorrect since a stack is not