Logging frameworks like Log4J allow us to send logs to a multitude of destinations. The code responsible for logging to a destination is usually encapsulated into seperate classes.
Without inheritance
With inheritance
When to use inheritance:
- IS-A relationship
- An Employee is a Person
- A BumperSale is a Sale
- A Square is a Shape
- IS-LIKE-A relationship
But if the relationship between them is HAS-A (eg: Car has an Engine), then we use composition instead of inheritance.
Reflections:
What is the relationship between the following objects?
- Bathroom - Bathtub
- Car - Engine
- Person - Professor
- Vehicle - Car
Discuss this post in the learning forum.
Note: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net
Commercial Links
- Buy programming books from our Amazon.com powered storefront.
- Earn as you browse. Sign up for Algoco.
Comments