Layers of Logic

Phase VII

The Four Pillars

Closing objects off, building on them, and letting them choose their own behaviour.

4 sections113 min of reading16 exercises

Protect object invariants, model honest parent-child relationships, and write callers against shared contracts. Then study wrapper conversions and all four nested-class forms, including their access, capture, and lifetime rules.

When you finish this phase you can

  • Protect invariants with operations instead of exposing fields through routine setters
  • Apply private, package-private, protected, and public access accurately
  • Trace superclass construction and use super for constructors and parent implementations
  • Separate compile-time overload selection from run-time override dispatch
  • Choose an abstract class or interface from state, hierarchy, and capability needs
  • Expand boxing and unboxing to diagnose identity, null, overload, and performance traps
  • Choose among static nested, inner, local, and anonymous classes by access and lifetime
  • Explain why lambdas replace many anonymous-class uses but are not anonymous classes
  1. 7.1Encapsulation, Inheritance, Packages, and `super`Protect an object's rules and move genuinely shared behaviour into a parent class.EncapsulationInheritanceCore28 min4 exercises
  2. 7.2Abstraction, Polymorphism, Abstract Classes, and InterfacesUse one parent type while each child object provides its own behaviour.PolymorphismAbstract classInterfaceCore30 min4 exercises
  3. 7.3Wrapper Types, Autoboxing, and POJOsSee when Java converts between primitives and wrapper objects, and avoid equality and null errors.AutoboxingPOJOCore26 min4 exercises
  4. 7.4Static Nested, Inner, Local, and Anonymous ClassesChoose a nested-class form from the data and enclosing object it needs to access.Anonymous classInner classCore29 min4 exercises