Gregory M. KapfhammerAssociate Professor of Computer Sciencehttp://www.cs.allegheny.edu/~gkapfham/ |
Justin Carulli, Lab 2
Hierarchies that follow the Liskov Substitution Principle have classes that are parent classes to lower classes, though the parent classes do not know it. Thus, all of the properties of the parent class remain the same while a derived class adds onto those properties. This prevents the changing of the source code of the parent classes, all the while updating and still utilizing the code efficiently. The hierarchy created in this laboratory does, in fact, conform to the Liskov Substitution Principle because none of the code was changed from class BankAccount to develop classes CheckingAccount and SavingsAccount. These lower classes were able to manipulate the characteristics from the upper class without the upper class knowing or adapting, so therefore this hierarchy is valid in terms of the Liskov Substitution Principle.Functions that use pointers or references to base classes must be able to use objects of the derived class without knowing it.
After compiling SavingsAccount and getting an error for attempting to use the balance variable in the super class BankAccount, I realized that the variable was declared as private. I then consulted with a classmate and then discovered that the getBalance method in BankAccount could achieve what I wanted.
The most difficult aspect of inheritance for me to understand was the concept that I could call a method with an object when the method was in a class higher on the hierarchy than the object's class. After doing this lab, however, I now realize that the lower classes do indeed have all the traits from the higher classes, and thus I can call a method that is higher up on the higherarchy with an object that is an instance of a lower class.
Justin Carulli
Link to this Page
- Lab 2 Notebooks last edited on 10 February 2005 at 11:33 am by aldenv244.allegheny.edu