Page 1 of 1

Is this bad programming?

Posted: Mon Nov 20, 2006 10:37 am
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.

Posted: Mon Nov 20, 2006 11:29 am
by volka
Might be good might be bad. Hard to tell from this small code snippet.

Posted: Mon Nov 20, 2006 12:10 pm
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.

Posted: Mon Nov 20, 2006 3:11 pm
by feyd
I have to agree with volka here, the sample is too small to say either way.