Forum Moderators: coopster

Message Too Old, No Replies

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

Object Oriented Programming, Design Patterns, Class Structure

         

centenial

12:28 am on Oct 13, 2008 (gmt 0)

10+ Year Member



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!

cameraman

5:52 am on Oct 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would definitely instantiate it in the Base class over the descendants, or maybe even have the Base class extend the Mysql class.