Why Object Oriented
- If you want to use any 3rd party code your going to anyway
- You can use standardized solutions to solve common problems (Design Patterns)
- Ability to easily gather data and the functions that work on it
- If properly used
Why Not Object Oriented
- There are fewer PHP developers with good OO knownledge
- Its easy to design more complicated systems then needed
- Less experience means a whole new set of mistakes to make
So lets use OO
- Its my workshop and I don't do much straight procedural code
- Things to keep in mind when doing OO Design:
- Design a Solid API
- Document you code
- Each class should do one thing well
- Keep things simple
- Avoid constants and Globals when possible
- Layer your Application
- Use inheritance but only for a few generations
- Use Design patterns
Design Patterns
in essence, design patterns are simply "down to earth"; good common sense. A collection of the best solutions to problems that software designers encounter again and again in their daily work. Given a little thought, design patterns are really an expression of the obvious, about which there's not much room for debate Harry Fuecks, phpPatterns
Our Major decisions
- What are the layers of our application ... Maybe
- Data Access (Model,Data)
- Control (Controller,Logic)
- Presentation (View)
- Can we use 3rd Party (Open Source) components for any or part of the layers ... Maybe
- Data Access:
- Control:
- Presentation:
- Smarty - own mini language
- Flexy - multiple own mini languages or just plain php
- Savant - plain old php
Lets start with the Data Access Layer and then use them to Build models
- I like using DAO if I don't already have a framework that does the gruntwork for OR mapping
- This dao code uses and is based of sample code from phpPatterns
-
- Our simple Database
- DAO Code:
A simple front controller that runs page contollers
Presentation Layer Using Savant Templates