Object Oriented Design Workshop

Joshua Eichorn

Creator of phpDocumentor, Senior Architect Uversa Inc.

The Project

Design Considerations

Why procedural

  • We can meet the current needs quickly and cheaply with most any php developer
  • Its easy to find php developers with procedural knownledge if we need to hire future support
  • Low complexity
  • Its still possible to use some basic off the shelf components like Smarty or Savant to handle templating

Why Not procedural

  • Few projects stay small
  • Most 3rd party tools are OO so you'll have a mix of OO code anyway
  • Harder to design with reusabiilty in mind
  • Greater chance for code duplication, many places for security related bugs

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

Lets start with the Data Access Layer and then use them to Build models

A simple front controller that runs page contollers

Presentation Layer Using Savant Templates

Thanks for coming

Slides and code are online at: http://blog.joshuaeichorn.com/presentations/