Re: Re: Constructor usage
| From: | Peter Pei | Date: | Mon, 05 Apr 2010 13:47:48 +0000 |
| Subject: | Re: Re: Constructor usage | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-303836@lists.php.net to get a copy of this message | ||
On Sun, 04 Apr 2010 17:46:19 -0600, Nathan Rixham <nrixham@gmail.com> wrote:
Larry Garfield wrote: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.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?