previous | start

## When Not to Use Inheritance

- Java standard library:

      public class Stack<T> extends Vector<T> // DON'T
      {
         T pop() { ... }
         void push(T item) { ... }
         ...
      }

- Bad idea: Inherit all `Vector` methods
- Can insert/remove in the middle of the stack
- Remedy: Use aggregation

      public class Stack<T>
      {
         ...
         private ArrayList<T> elements;
      }

previous | start