views:

116

answers:

1

Hello,

I think I am experienced procedural PHP programmer. I've implemented a few bigger projects. Now I would like to try OOP PHP on lesser one (framework for DB import/export + user authentication). Since I've never tried OOP on such a project I have problem with object design.

I would like to implement the framework the way, I'll just need to create one instance of the object to use whole framework. I would also like to keep the code well arranged, so I won't implement only one class for all methods/properties.

How could I split one big class in to few lessers to keep them organized (in more php files)?

I think I'll have to implement one base class and then extend it using the others. But that way I'll have many of small classes, not big one.

How would you solve this problem?

I hope I explained the problem well.

Thanks for any help.

+5  A: 

I have written and maintained huge monolithic libraries for many years, and I'm way happier since I moved away from it. Take my advice: Break your application down into as small classes as possibly makes sense. It's good for organizing, as well as memory usage (a huge PHP class definition can eat up a lot of RAM, and RAM is a limited resource in a PHP script).

Use PHP 5's autoloading mechanism to load only those classes thart you need in the current context.

I think the way Zend Framework is organized and built is quite good. You may want to take a look at how they designed their classes, and how they organized the immense amount of functionality in the framework.

As for how to organize tools and helper objects and libraries, I asked that question a few weeks back and got very good feedback. I'm still not done reading it, actually.

Pekka
Pekka, i love your answers, i've noticed that you are very active in the PHP tag on SO.... i have seen you answer in most questions that I myself was going to answer - just faster. :)
Jacob Relkin
Cheers Jacob! I think I have come across several answers of yours where it was the other way round :)
Pekka
+1 for the Zend frameworks' design and architecture.
Mr-sk
Thanks for the answer. It seems to be good idea to break code into many small classes for a framework programmer, but I am not sure if it's comfortable enough for user of the framework. (even with autoloader function implemented).User will have to initialize many instances of many classes (in case of bigger framework). Is this the way how Zend Framework works?
Petr Peller
As I reviewd your question, I found name of my problem (singleton pattern). There is also nice feedback as you said. Thanks a lot.
Petr Peller