Is this bad programming?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Is this bad programming?

Post by timclaason »

I have an Intranet web app that has gotten to be quite bloated, so I have child classes for various components of the app (administration area, etc).

I have a scenario in which the parent is calling a method from the child.

It looks like this:

Code: Select all

$this->obj = new childClass;
$this->obj->nameOfChildMethod();
I'd never really done that before, and I was wondering if this is the proper way to do it, or if there's a better way to do it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Might be good might be bad. Hard to tell from this small code snippet.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Putting an object inside an object is called composition and is very much encourages over inheritance as you can swap out objects for others at runtime. Although the snippet you have provided is insufficient to make a proper judgement, chances are what you are doing is a good thing.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have to agree with volka here, the sample is too small to say either way.
Post Reply