News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

NetTuts.com:
SOLID Part 2 - The Open/Closed Principle
January 21, 2014 @ 12:45:29

On NetTuts.com today they continue their look at the SOLID development principles with the next letter in the sequence - O for Open/Closed Principle. The first part of the series, covering "S" (the Single Responsibility Principle) can be found here.

The Open/Closed Principle, OCP in short, is credited to Bertrand Mayer, a French programmer, who first published it in his book Object-Oriented Software Construction in 1988. The principle rose in popularity in the early 2000s when it became one of the SOLID principles defined by Robert C. Martin in his book Agile Software Development, Principles, Patterns, and Practices and later republished in the C# version of the book Agile Principles, Patterns, and Practices in C#. What we are basically talking about here is to design our modules, classes and functions in a way that when a new functionality is needed, we should not modify our existing code but rather write new code that will be used by existing code.

They start with a look at OCP in the overall SOLID context and an example of an obvious violation of the principle. Some example code is provided showing a "Progress" class that's bound to at "File" implementation, not abstracted. They offer three different options for solving the issue:

  • Take Advantage of the Dynamic Nature of PHP
  • Use the Strategy Design Pattern
  • Use the Template Method Design Pattern

Each of the above comes with example code and some with illustrations of the structure they create.

0 comments voice your opinion now!
solid design principles open closed tutorial introduction

Link: http://net.tutsplus.com/tutorials/php/solid-part-2-the-openclosed-principle

blog comments powered by Disqus

Similar Posts

Refulz Blog: Traits in PHP 5.4 - Why we need Traits

Matthew Leverton\'s Blog: How to add a custom CAPTCHA to phpBB2

Pim Elshoff's Blog: SOLID design

Zend Developer Zone: Tutorial : Using Zend Framework Without PDO

PHPMaster.com: Mapping with Geocoder PHP and Leaflet.js


Community Events





Don't see your event here?
Let us know!


language tool symfony interview laravel version composer framework update library voicesoftheelephpant community introduction podcast series package mvc release security opinion

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework