Re: Is creating anonymous objects bad practice?
- From: "Arved Sandstrom" <asandstrom@xxxxxxxxxxxxx>
- Date: Sat, 29 Nov 2008 15:24:46 GMT
"Eric Sosman" <esosman@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:ggqca0$v8c$1@xxxxxxxxxxxxxxxxxxxxxx
Andreas Leitgeb wrote:
Arved Sandstrom <asandstrom@xxxxxxxxxxxxx> wrote:
new LogThis().log("Log this string");
Unless the log-method really really needs an instance
of its class, this is almost as bad as the constructor
thingie. "Almost" (and not "entirely"), because at least
we do not use incomplete objects that way.
Just make log static and do Logthis.log(...);
Well, there's the possibility that Log might have more
than one constructor:
new LogThis().log("Log this string");
new LogThis("foo.log").log("Log this string");
new LogThis("foo.log", LogThis.PRIORITY_MEDIUM)
.log("Log this string");
Even so, though, it looks pretty silly to (presumably)
create/open, write to, and flush/close a log in the
LogThis constructor. Makes retaining a LogThis instance
sort of useless, no?
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
Arguably logging is a bad example anyway. We are reading too much into it.
Namely, the points you made about what that LogThis ctor would have to do,
unless the log() method did all of it, which is also ungood.
AHS
.
- 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: Andreas Leitgeb
- Re: Is creating anonymous objects bad practice?
- From: Eric Sosman
- Is creating anonymous objects bad practice?
- Prev by Date: Re: Best metric available
- Next by Date: Re: Is creating anonymous objects bad practice?
- Previous by thread: Re: Is creating anonymous objects bad practice?
- Next by thread: Re: Is creating anonymous objects bad practice?
- Index(es):
Relevant Pages
|