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!

 

 

Link to comment
Share on other sites

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); }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.