Re: Is creating anonymous objects bad practice?
- From: Lew <noone@xxxxxxxxxxxxx>
- Date: Sat, 29 Nov 2008 14:45:54 -0500
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
.
- Follow-Ups:
- Re: Is creating anonymous objects bad practice?
- From: Arved Sandstrom
- Re: Is creating anonymous objects bad practice?
- References:
- Is creating anonymous objects bad practice?
- From: Peter D.
- Re: Is creating anonymous objects bad practice?
- From: Arved Sandstrom
- Re: Is creating anonymous objects bad practice?
- From: Lew
- Re: Is creating anonymous objects bad practice?
- From: Tom Anderson
- Is creating anonymous objects bad practice?
- Prev by Date: Re: Quirk with generics
- Next by Date: Re: Simple integer factorization algorithm
- Previous by thread: Re: Is creating anonymous objects bad practice?
- Next by thread: Re: Is creating anonymous objects bad practice?
- Index(es):