Open-Closed Principle
Quickstart Guide
SOLID
“ Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. “
https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle
Add new functionality without changing the existing code
What do we aim for ?
No need to disturb its clients
Dependency
Flow of Control
“Protect Controller from changes of Presenter”
For example, we should ...
Concept
Meyer's open/closed principle
Inheritance
Problem:Tight Coupling
the subclasses depend on implementation details of their parent class.
Meyer's open/closed principle
Inheritance
Example 1-1
Overriding...
Multiple Inheritance...
Concept
Robert C. Martin's open/closed principle
Polymorphic
Interface
allow different implementations which you can easily substitute without changing the code that uses them.
Robert C. Martin's open/closed principle
Polymorphic
“Composition over inheritance”
Robert C. Martin's open/closed principle
Polymorphic
Example 2-1
Consider it ....
Robert C. Martin's open/closed principle
Polymorphic
Example 2-1
Consider it ....
! Keyword Class shouldn't consider the implementation detail of file/api reader.
Change the implementation detail of reader will influence Keyword
! File/Api reader can't be reused.
It may violate DRY in future
Robert C. Martin's open/closed principle
Polymorphic
Example 2-2
Make accountability clear
Made with Slides.com