2. Sam Hennessy
• Originally from the UK
• Now live in Denver, CO
• Software Architect at i3logix
• Ex-Pro Services Consultant For Zend
• Regular at Front Range PHP Users Group
2
4. What is it?
Part of SOLID
Protect your system from change
Do you already do it?
4
5. SOLID
S Single responsibility
principle
O Open/closed principle
L Liskov substitution principle
I Interface segregation
principle
5
D Dependency inversion
principle
7. And I Care Why?
Maintenance
Let your
Customer
users bridge a
customization
feature gap
Competitive Preventing
edge the "FORK"!
A-la-cart
feature
offerings
7
I hope to enable you to add some consistency by formalizing your thinking around OCP
Risk of making changeLessened by good automated testing coveragePlatforms Amazon vs. GoogleTwitter
You can apply the principle reactively
Let’s take a look at techniques for each layer
Traditional ideas of OCP what you be able to write the class code once and never have to come back to edit itThese techniques focus on this level changeSome of my application level techniques kind of blur the linePrevent changes to a classDoesn’t prevent change to the app, unless you are using DI or something like it
Small is fast when it comes to changing direction10 executable lines is a good target, 20 the max (obviously there are always exceptions)
Just one client can mess it up for everyone
Traditional ideas of OCP say that globals break OCPThese are points of view that are just thinking about riskYou are introducing risk that other parts of the system will break this code
Making your code ignorantAbstracting – to
Imagine this all over your application.Then we want to add FireBug/FirePHP logging support for our Ajax calls
Also called Composite Reuse Principle
What’s your goal
Can anyone think of any more class level techniques
Lots of examples from ZFThink how this has helped word press
Signal & SlotsPub/Sub
Cross cutting concernsFlow 3
Can anyone think of any more APPLICATION level techniques
Message bus
PubsubQueueTrue broadcast
Martin FowlerIsolate the assumptions scattered around the code to a single element (by assumptions, you assumed they wouldn't need to change) E.g. You are echoing all over the code, but you need to support encoding to jsonThis will reduce the risk for the big change Or start from scratch