Jump to content

Making PHP Classes Play Nicely With Each Other (OOP Pattern Question)


centenial

Recommended Posts

Hi all,

 

I have a PHP OOP design question. I've done some searching in google, but wasn't able to turn up anything concrete. I'm hoping some experts can point me to the most elegant solution. :)

 

I have a set of classes. All of my classes "extend" an abstract class called Base. (This class reads a config file, has a basic set of common methods, and sets up needed parameters)

 

Most of my classes need a class called Mysql to perform database operations.

 

Is the best way to access the Mysql class to pass it in the __constructor in each of my child classes, or to instantiate it in my Base class, and assign it to a public property? Or perhaps there is a better way altogether?

 

I'm really looking for the best way to do this, so thanks in advance for your advice!

 

 

Personally i prefer the singleton pattern over the registry pattern and all my singleton pattern have a static get instance() method.  I never got what the registry pattern provide as a benifit over the singleton pattern.

I usually have a BaseDao class which contains the connection to my database. All of my Data(base) Access Objects extend from BaseDao which contains methods like: find(), findUnique(). UserDao (an extension of BaseDao) would defined methods like: getUser(User $person) { $this->findUnique($person); }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.