Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Chapter 6: Inheritance and Abstract Classes Chapter Topics 6.1 ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CS151 Object-Oriented Design<br />
Dr. Kim<br />
• Considering the Stack class inherits all Vector methods, the above design choice is a bad<br />
idea because it violates the principle of data abstraction. (The remove <strong>and</strong> add operations<br />
are done on the top element only.) However, this version of stacks can insert/remove in<br />
the middle of the stack using the inherited Vector methods.<br />
• Remedy: Use aggregation<br />
public class Stack<br />
{<br />
...<br />
private ArrayList elements;<br />
}<br />
39