Notes: Thinking in Java 3rd Edition - Chapter 1
Post Info Wednesday, July 1st, 2009 9:00 pm by Cody Print Print this page

Just a few notes from Bruce Eckle’s Thinking in Java 3rd Edition, mostly terminology that I forgot the proper term for.

Chapter 1: Introduction to Objects

Why Hide Implementation
1. To prevent client programmers from touching things they shouldn’t touch
2. Allow library designers to change the internal workings without affecting the client programmer

You can hide implementation with access specifiers like public, private, and protected.

Reusing the Implementation
Composition (”has a” relationship; a car has an engine) occurs when you have an existing class in a new class.  If it happens dynamically, it is aggregation.

Is-a vs is-like-a Relationship
If the derived type is the same type as the base class and has the exact same interface, it is called pure substitution and is known as the “is-a” relationship.  If you decided to add new methods to the derived class, then it is a “is-like-a” relationship.

Early Binding vs Late Binding
For early binding, the compiler knows at compile time what code will be executed.  For late binding (like OOP languages), the code being called isn’t known until run time.

Polymorphism
Definition: treat an object not as the specific type that it is, but instead as its base type
Treating a derived type as though it were the base type is known as upcasting.  This occurs when doing polymorphism.

Interface vs Abstract Class
Abstract classes can have non-abstract methods implemented and leave the abstract methods to be implemented by the derived class.  Interfaces cannot have methods implemented.  You can combine multiple interfaces together whereas you cannot inherit from multiple regular or abstract classes.

Useful link

Downcasting
When you retrieve an Object from a container and need to return it back to the original type, you need to perform downcasting.  This isn’t true if you use parametrized types.

What is OOP?
Technically OOP is about abstract data typing, inheritance, and polymorphism.

Leave a Reply

Get updates as often as we post! Subscribe to our full feed or comments feed.