previous | start

## When Not to Use Inheritance

- Java standard library:

      public class Stack extends Vector // DON'T

      {

         Object pop() { ... }

         void push(Object item) { ... }

         ...

      }

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

      public class Stack

      {

         ...

         private Vector elements;

      }

previous | start