Re: Re: Constructor usage

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

 



On Sun, 04 Apr 2010 17:46:19 -0600, Nathan Rixham <nrixham@xxxxxxxxx> wrote:

Larry Garfield wrote:
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?


Other than theoretical reasons, one practical reason to have getters and setters is to make live easier for IDE's.

I never thought the above two are in conflict. Usually parameterized constructors are provided along with getters and setters - each is used for good reasons.

--
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