Object Oriented Programming II
See csse2002 for course logistics. Continues 2026-03-05-object-oriented-programming-i.
Today’s outline
- Object Oriented Programming II
- Specification
Recap: the four (five) pillars
Last week covered Objects/Classes/OOP, Encapsulation, Inheritance, and Abstraction. This week adds Polymorphism, plus revisits/extends a few Week 2 topics in more depth.
Interface vs abstract class
Week 2 left the “when to use which” comparison as homework — now covered properly in java-abstraction.
Revising encapsulation
A quick recap of java-encapsulation’s Person example — bundling fields with the methods that access them, restricting direct access via private + getters.
Mutable vs immutable classes
See java-mutability — object state that can (mutable) or cannot (immutable) change after construction, and the arrays/lists gotcha where final only protects the reference, not the contents.
Polymorphism
See java-polymorphism — compile-time (overloading), runtime (overriding/dynamic dispatch), and subtype polymorphism.
Casting
See java-casting — primitive widening/narrowing casts, and reference upcasting/downcasting.
Specification
See java-specification — Javadoc, restrictiveness, generality, clarity, formality, contracts, and defensive programming.