Re: Is creating anonymous objects bad practice?



"Lew" <noone@xxxxxxxxxxxxx> wrote in message
news:ggs65i$op$1@xxxxxxxxxxxxxxxxxxxx
Tom Anderson wrote:
Hold on, hold on, the issue in this thread isn't about incompletely
constructing objects, it's about the other fork of Arved's succinct
putting - that constructors should not do anything else. Consider:

public class LogMessage {
public LogMessage(String msg) {
System.err.println(msg) ;
}
}

Which is used OP-style like this:

doSomething() ;
new LogMessage("did something") ;

There's no risk of incomplete construction here, but i think we'd all
agree that this is bad style nonetheless.

I agree. One of the risks of putting too much into a constructor is that
the actions are performed by an incompletely-constructed object, as an
exemplar of the engineering decision that goes into that. It is meant as
a distinction from maintainer confusion or expectation. It is certainly
not the only problem with doing such things.

--
Lew

And I believe we are on the same *** of music. When I said that I (or
anyone else) expect a constructor to only initialize an object, that
expectation exists because of sound OOP principles. However, there's no
question that if those (over any other) principles are not followed,
confusion results...among other things.

AHS


.


Quantcast