Ashley Sheridan wrote: > Hi All, > > I know that a class can only inherit from one other single class in PHP, > but how would I go about simulating a multiple class inheritance? For > example, if I had several small classes that dealt with things like form > generation, navbar generation, etc, how could I create a class in which > these all existed? > > Or am I thinking about this the wrong way? Should I have keep the > smaller classes, and have one larger object containing instances of each > as and how are necessary? > > I've used classes before, but I'm fairly new to class inheritance, and > more particularly, the complex inheritance like I describe here.
"is a" and "has a" normally solves these composition vs inheritance questions in a second or two. perhaps a bit of studying on composition vs inheritance and common OO design patterns would be suited; also consideration for separation of cross cutting concerns | in fact a bit of reading up on java design patterns would be recommended; it'll stand you in good stead. the core J2EE Patterns catalog is well worth a look: http://java.sun.com/blueprints/corej2eepatterns/index.html Also Martin Fowler's pattern catalogue and indeed articles are worth going over: http://martinfowler.com/eaaCatalog/ and for a general overview: http://en.wikipedia.org/wiki/Category:Object-oriented_programming finally, from the very limited details it sounds like implementing an 3-tier architecture where you stick application code in one tier and presentation code in another would help abstract things a bit for you; the classes you've mentioned sound very much like Utility or Helper classes which would normally be called by methods which couple all the functionality together. Each class and method needs to be considered on a case by case basis; many will be able to be called statically and thus no composition is needed; on occasions where you need to call several methods from one instance within a single method then instantiation within that method will suit; and when you need to access instance based functionality across multiple methods in a class then composition (or perhaps inheritance : see is-a has-a) will suit. regards! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php