More actions
Created page with '== Open & Closed Principle<br> == Description:<br> As the name itself, it's a principle instruct us how to close the main base behaviors of the original classes by preventi…' |
No edit summary |
||
Line 1: | Line 1: | ||
== Open & Closed Principle<br> == | == Open & Closed Principle<br> == | ||
=== Introduction:<br> === | |||
As the name itself, it's a principle instruct us how to close the main base behaviors of the original classes by preventing almost direct modifications, also to open existing classes to extend or make some changes by subclass and override on them | As the name itself, it's a principle instruct us how to close the main base behaviors of the original classes by preventing almost direct modifications, also to open existing classes to extend or make some changes by subclass and override on them.<br> | ||
=== Description:<br> === | |||
Class can be subclassed<br> | #Class can be subclassed for extension<br> | ||
#Class' behaviors can be overriden<br> | |||
#No modification is on the locked behaviors of base class (<u>related open behaviors aren't</u>)<br> | |||
#Modifications are on subclass<br> | |||
=== Specification: === | |||
*Description #1 and #2 means that base class must assure the accessibilities and inheritance | |||
*Description #3 and #4 means that we have 2 methods for the base class extension: | |||
#Allow the closed action might be overriden and reused on subclass | |||
#Allow some actions open on base class so that those actions might happen inside the closed action | |||
=== Example:<br> === | |||
<br> | <br> |
Revision as of 02:28, 22 April 2010
Open & Closed Principle
Introduction:
As the name itself, it's a principle instruct us how to close the main base behaviors of the original classes by preventing almost direct modifications, also to open existing classes to extend or make some changes by subclass and override on them.
Description:
- Class can be subclassed for extension
- Class' behaviors can be overriden
- No modification is on the locked behaviors of base class (related open behaviors aren't)
- Modifications are on subclass
Specification:
- Description #1 and #2 means that base class must assure the accessibilities and inheritance
- Description #3 and #4 means that we have 2 methods for the base class extension:
- Allow the closed action might be overriden and reused on subclass
- Allow some actions open on base class so that those actions might happen inside the closed action
Example: