CSE Roadmap

Core tier · about 3 hours · 7 parts

Part 1 of 7 · 1 min read

Why this page comes fourth

In this module you will

  • Explain white-box reuse (inheritance) and black-box reuse (composition).
  • Say why inheritance breaks encapsulation, with a worked example.
  • Build a wrapper that reuses a class by composition and forwarding.
  • Apply the rule "favour composition over inheritance", and know when inheritance is safe.
  • Explain delegation and when it helps.

Module 3 showed that sharing an interface lets objects be swapped. This page covers the other kind of sharing, reuse of code, and why the book authors warn about it. The sources are "Design Patterns" (GoF), chapter 1, and "Effective Java" (EJ) Item 18. Code was compiled and run before it was written here. Numbers marked "made up" only show the idea.