I am creating some objects which require complex procedures to set up the variables. I can think of three different ways to code this. Does anyone have comments on pros and cons of each approach?
class TestClass1 {
var $foo;
var $bar;
// Constructor
function TestClass1() {
$this->createFoo();
$this->createBar();
}
function createFoo()
{ $this->foo = 'something' }
function createBar()
{ $this->bar = 'something' }
}
class TestClass2 {
var $foo;
var $bar;
// Constructor
function TestClass1() {
$this->foo = $this->createFoo();
$this->bar = $this->createBar();
}
function createFoo() {
//Statements
return $foo;
}
function createBar() {
//Statements
return $bar;
}
}
class TestClass3 {
var $foo;
var $bar;
// Constructor
function TestClass3() {
$this->foo = new Foo();
$this->bar = new Bar();
}
}
class Foo {
// Constructor
function Foo() {
//Statements
}
}
class Bar {
// Constructor
function Bar() {
//Statements
}
}