Do you do OOP?

Do you?

If you do, what are the steps you take from design to actual production?

I’m a lonely programmer and I keep repeating codes. Haven’t realized the power of OOP yet cause I don’t know how to start. Don’t know what are the classes I need. Don’t know how to design classes that could be used in other projects. :blush:

PHP’s manual has a bit on OOP:

If you do not insist on writing code from scratch, use an OOP framework like CodeIgniter, Symfony, or CakePHP

My experience says too that OOP is very good.
I like the style of book .
If you want to use a framework I thing that it is obvious to practice first and then to use it at a production evironment.
Look also at

What are people’s thoughts on Yii Framework?

To design classes that could be used in other projects, you should, for example, not have dependencies inside your class, instead add those dependencies after object creation
$model = New Model();

I use Yii and my opinion is that is a good framework.
It use OOP and MVC patern, you may as example extend a base class of the framework or use and extend other classes or just create your own.
You may look here

thats a very nice book you recommended dimis283 :slight_smile:
Yii is something new to me. how does it compare to those popular ones like zend, cakephp, codeigniter?

i guess to design a software, we should start with a UML diagram? any recommended open source solution for that? like i’m using mysql workbench for doing ERD diagrams.

Yii is relative new but has its base at prado, I used CI and I thing Yii is a better choice.
As I notice have many simiralities with cake as they are from Ruby on Rails as they saying. has support of uml and php.

I tend to model my data first. Recently, I just start with an ORM immediately. Data access and updating is something that happens all throughout your app, so its important to centralize all the functionality in a single place right off the bat. Otherwise, you end up with queries in a bunch of places they shouldn’t be and code responsibilities can end up mixed pretty badly. OOP itself doesn’t solve these design issues or prevent you from doing things you shouldn’t.

These day and age, developers don’t do OO design as much as before. It’s not like we’re building from scratch. I’d say savy developers are more like “Open Source Architect”. They would add the ingredients needed to make the developers to code faster! So, most of the time you just need build few classes that extend their framework. I hardly call Data model as OO design but if you do then this is where majority of OO design would fit in.

If you ever do java then these 3 are the hot tech to learn

JSF + Spring + Hibernate

By learning these, you’ll automatically understand OOP.

Ive been struggling to understand OOP for a while, and after messing around so long I’m slowly beginning to catch on. Be patient with learning it, it’s kind of tricky.

I think the first thing you should try doing is making a MySQL Class, so that inserting and selecting is really easy, then you use 1 object of the mysql class through your entire aplplication.

OOP alone won’t make your code better, you can write non-cohesive and highly coupled code in OO languages, just as you can break OO best practices while using OOP.

Brush up on OOD principles:

Decomposing an object isn’t easy, nor can be it be easily explained, each problem is different. What good OOP will facilitate is easier refactoring, so further decomposition of an object API becomes much easier.

Just remember DRY KISS…keep everything extremely simple…no method greater than 25 SLOC lines or whatever your comfortable with…

Maybe so, but I’d definitely say that the learning process does. It adds another dimension to the way you think about programming. If you write a program procedurally, then learn OOP to a decent level, write the program in OOP then write it again procedurally, it’s safe to say that all 3 versions will be very different.

Generally the 3rd (Procedural, after learning OOP concepts) will be neater and more structured than the 1st (Procedural, before learning OOP concepts), and the 2nd (OOP) and 3rd (Procedural Post-OOP) could be similar in some ways.

OOP seems to be a different way of organizing and orchestrating your applications flow. When I first started, I wrote functions for everything and they ended up everywhere. At that point I hated it. I’ve been sticking with it and, although I’m still noob I suppose, really like it. For me it is far superior to procedural in many circumstances. Of course, there are times procedural makes more sense than OOP but generally only when you are writing something on a smaller scale.

CodeIgniter is your friend, it forced me to use OOP and I haven’t looked back. I no longer re-write code as all my classes are very modular.

CI uses the MVC approach for development, very useful for finding a good starting point with your application development.

I am just getting to grips with oop. I am rewriting an ecommerce site to use it, and there are some cases when i don’t know whether to use a class or just keep calling a function/include.

For example, inserting the google analytics code. To insert a chunk of code like that (something that will never change, and will never be inherited from) is a class the best
option, or an include, or a function?. Which takes the least processing?

Another example - i have a function, checkSession which returns the value of a session var or false. Presumably a quick lookup like that should remain a stand-alone function?

Something like google analytics code would maybe be not be a candidate for a class, however I think the issue is also how you structure your site, do you want to mix php includes with classes for example? Therefore it could be wise to make a statistics class just to keep thing organised.

“checkSession” function seems to belong to a specific class, maybe a session or user class depending on your class structure…so avoid a stand alone function for this

It’s absolutely BAD choice using a PHP framework before knowing even basic OOP concepts, it’s will mess you up…

First, learn the OOP principles, then try to make simple applications using OOP, only after this try a PHP framework…

Try reading a book on OOP, because it will give you a more systematic learning, than on blogs.

I recommend these books:
Object-Oriented Programming with PHP5
PHP 5 Objects, Patterns, and Practice
The Object-Oriented Thought Process

danman, re the checksession example. I use that everywhere.
eg -
if user is logged, don’t show login tab, show account instead.
if basket is not empty, show checkout option
check if user tried to access the checkout page without logging in first (so it knows to redirect after login)
for the id of the basket to add lines to

do you suggest i add it as a function to all sorts of classes?

No not really…
A good approach could be to put the session handling in a class to be able to change that implementation if needed later on

class Session
public function __construct()

public function get($name)
if (isset($_SESSION[$name]))
return $_SESSION[$name];
return false;

And then the user class or basket class or something has specific methods
for example a “IsLoggedIn” method that uses the Session class…

if($user->IsLoggedIn())// do something