Constructor usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks.  Somewhat philosophical question here.

I have heard, although not confirmed, that the trend in the Java world in the 
past several years has been away from constructors.  That is, rather than 
this:

class Foo {
  public void Foo(Object a, Object b, Object c) {}
}

Foo f = new Foo(a, b, c);

The preference is now for this:

class Foo {
  public void setA(Object a) {}
  public void setB(Object b) {}
  public void setC(Object c) {}
}

Foo f = new Foo(a, b, c);
f.setA(a);
f.setB(b);
f.setC(c);

I suppose there is some logic there when working with factories, which you 
should be doing in general.  However, I don't know if that makes the same 
degree of sense in PHP, even though the OO models are quite similar.

So, I'll throw the question out.  Who uses example 1 above vs. example 2 when 
writing dependency-injection-based OOP?  Why?  What trade-offs have you 
encountered, and was it worth it?

--Larry Garfield

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux