You are viewing...

PHP OO thinking in a flash!

Updated on May 24, 2009 at the 19th hour
Posted under:

DISCLAIMER: All views are considered my own and you should not draw any conclusions on associates.

I've been doing some extensive PHP OOP lately and found that it is easier to discard many principles of OOP such as the Single Responsibility Principle. Single Responsibility (in a nutshell) is every object / function has one main responsibility. It is challenging to break the usual thoughts of procedural programming where everything is programmed from top down. Essentially, having a procedural style of programming means you are thinking like a computer.

Well, how can one start thinking about objects as people? So far, I've found PHPFreaks OOP (3 parts to it), Object Thinking, Code Complete 2, and Pragmatic Programmers: Journeyman to Master very good resources.

I think of every object as some type of room, person, or other metaphor. Some objects will be books (Data aggregators, structs), People (Managers, workers, etc.), and rooms (Lists, arrays, stacks, etc.). The point is if you think of an object as different materials, then you tend to see the classes, functions, and properties you need to write onto paper. Example is: I have a room full of books. I need this person to retrieve a book from a room and tell me what is the author's name. Book has the authors name, room has the book, person need to search the list to retrieve the book and finally 'gimme' the author' name. It is one way of looking at OO thinking, so you can come up with different associations and bound together.

You are using the real world as a model and attempting to replicate it, always remember that.
You just read "PHP OO thinking in a flash!". Please share if you liked it!
You can read more recent posts here.