Which of these OOP options should I use?

KathryndvRehrer

New Member
I have two classes ClassA and ClassB. ClassA always needs an template file name, and ClassB extends ClassA.In usual cases when a ClassB instance is created, the user has to specify the template file name. Like:\[code\]$classB = new ClassB('index');\[/code\]But now I created a ClassX which extends ClassA, and when the user uses ClassX, he must not specify anything. It's a class that just creates a button, so it knows by itself what the template file for this is like.So the user just wants to call:\[code\]$bttn = new ClassX();\[/code\]and internally the constructor of ClassA is called with 'button_template'.To do this, I see these choices:A)\[code\]public function __construct() { $tplName = func_get_arg(0); if (!isset($tplName)) { $tplName = 'button_template'; } parent::__construct($tplName);}\[/code\]Or B)\[code\]public function __construct($tplName='button_template') { if (!isset($tplName)) { $tplName = 'index'; } parent::__construct($tplName);}\[/code\]Or C)\[code\]public function __construct($tplName='button_template') { parent::__construct($tplName);}\[/code\]Which one is the best? And why?
 
Back
Top