Great Example of Open Closed Design Principle
I am big fan of design pattern article and love to read articles on design patterns and recently wrote about decorator design pattern in Java. Today I come across this good article on open closed design pattern, what I like most is there example and clear way of explanation, first example is true value and it will help you understand open closed principle very quickly and second example is also not bad.
One word about Open Closed principle is a design principle which says that a class should be open for extension but closed for modification. Benefit or Open Closed Design Principle:
1) Application will be more robust because we are not changing already tested class.
2) Flexible because we can easily accommodate new requirements.
How to make code extensible
Basic principle of making your code extensible and following open closed principle is providing object to class at run time and making use of polymorphism to invoke extended functionality.
If functionality is hard Coded than it wouldn’t be extensible but if you write interface and provide implementation of that interface at run time you make it extensible.
For detailed example see this link open closed design pattern on sanaulla blog.
Interview Questions you may like
Do you like Books?
If you love to read books here are few Java titles which is worth of money :
10 comments:
Java is evergreen applications. It has good future. the Interview Questionsrelated to java are big help to its aspirants.
Blogs by Country
Blogs Directory
link directory
Blogpedia
Blogging Critic
Blog Directory
Post a Comment