Open-Closed Principle: Extend Behavior Without Endless Conditionals | Java 11
Description: Adding a new delivery policy should not require another branch in every caller. Apply the Open-Closed Principle to a Java quotation engine with explicit registration, preserved existing results and honest unsupported cases.
WHAT YOU'LL LEARN
- Choose an extension point for a demonstrated family of changes.
- Separate adding a policy from changing dispatcher logic.
- Preserve old results and fail explicitly for unregistered or invalid behavior.
CHAPTERS
00:00 Extend the behavior that actually varies
00:57 A conditional is not automatically a design failure
01:46 Capture the existing behavior before adding the extension
02:31 Define the smallest useful rate capability
03:12 Move each existing calculation into its own rule
03:58 Registration chooses implementations; dispatch uses the contract
04:46 Unsupported behavior must not become a silent default
05:35 Add rail without editing the dispatcher method
06:18 Run all three modes and verify old results
07:02 Test boundaries around the extension point
07:53 Choose what stays stable, and allow the rest to change honestly
08:42 Extend a real variation point without hiding the costs
Java for Software Engineers | Episode 11: Open-Closed Principle: Extend Behavior Without Endless Conditionals
Helpful background: Runtime polymorphism, composition, SOLID overview and coherent responsibilities.
Next in this course: Episode 12 - Liskov Substitution: When Inheritance Breaks the Contract
Subscribe to Think Make Explore for practical Java tutorials and software design lessons.
Example notes: Prices are fictional examples; no shipment is booked.
LEARNING REFERENCES
SOLID overview and open-closed principle: https://web.archive.org/web/20210412201110/http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Java21 interface contracts: https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html
Java21 immutable map snapshots: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map)
#Java #OpenClosedPrinciple #JavaTutorial Close description
WHAT YOU'LL LEARN
- Choose an extension point for a demonstrated family of changes.
- Separate adding a policy from changing dispatcher logic.
- Preserve old results and fail explicitly for unregistered or invalid behavior.
CHAPTERS
00:00 Extend the behavior that actually varies
00:57 A conditional is not automatically a design failure
01:46 Capture the existing behavior before adding the extension
02:31 Define the smallest useful rate capability
03:12 Move each existing calculation into its own rule
03:58 Registration chooses implementations; dispatch uses the contract
04:46 Unsupported behavior must not become a silent default
05:35 Add rail without editing the dispatcher method
06:18 Run all three modes and verify old results
07:02 Test boundaries around the extension point
07:53 Choose what stays stable, and allow the rest to change honestly
08:42 Extend a real variation point without hiding the costs
Java for Software Engineers | Episode 11: Open-Closed Principle: Extend Behavior Without Endless Conditionals
Helpful background: Runtime polymorphism, composition, SOLID overview and coherent responsibilities.
Next in this course: Episode 12 - Liskov Substitution: When Inheritance Breaks the Contract
Subscribe to Think Make Explore for practical Java tutorials and software design lessons.
Example notes: Prices are fictional examples; no shipment is booked.
LEARNING REFERENCES
SOLID overview and open-closed principle: https://web.archive.org/web/20210412201110/http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Java21 interface contracts: https://docs.oracle.com/javase/specs/jls/se21/html/jls-9.html
Java21 immutable map snapshots: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html#copyOf(java.util.Map)
#Java #OpenClosedPrinciple #JavaTutorial Close description




