views:

230

answers:

4

I'm trying to set up a new class for my web application, rewriting my code starting from original procedural programming. Since I need to populate my object using many different(complex) queries, and this object'll be stored in session, I decided to create another static class containing all long queries.

Is it more convenient to define as "static" a function within the same class without creating a new one? My goal is to have an object lighter as much as possible... thanx

A: 

Hello!

You should break up your problem domain in smallest parts possible and create classes accordingly. Not one 'big' class that is supposed to handle all.

Each class handles one specific part of the overall problem you're trying to solve.

I think you'll find this an easier approach to your problem.

Tony

Tony
A: 

Try considering that every table in your db is a class and describe it in php. So the class propaply will have som methods for saving, reading, updating, and some static methods to retrieve array of objects of that class.

Piotr M.
If using this approach, I highly recommend using a third-party ORM framework such as Doctrine or Propel.
jkndrkn
A: 

It sounds like you might be combining the functionality of database access with a business logic class.

When not using an ORM layer and working with smaller applications, I will generally create a single class responsible for all interactions with the database. This class will contain reusable bits of queries to be called upon by methods within that class. I declare these bits as private static attributes. This class does not store any data. Rather, it simply passes data to the calling script or class. To reduce memory consumption, I implement this class using a Singleton pattern to ensure that any script that needs to use this class uses the same instance of the class and does not allocate additional memory. Since the class is not used to store global data, the perils of using a singleton in this case are avoided.

Also, I will advise you to not worry too much about memory consumption unless you are working with limited hardware resources and/or a heavily trafficked site.

jkndrkn
ok.. You've focused my problem and answered my question. Thank you very much
cesko80
A: 

I think that my question could be rewritten as: is a static function (and all his members) copied in a serialized child object saved in a session var? I think that it makes sense only if I can find non - static members in a object...

cesko80