Tony said:
a) I did not say that mutable types are poor form.
Sorry, that was my impression.
b) I did say that passing or returning a mutable type is poor form, and I
stand by this assertion (it's easily proven). It can 'always' be done
better.
Discussing the cases where it is nice form is probably not worth doing.
c) Lots of 'ifs' is also poor form. My general rule is that 4 or more should
be replaced by the strategy design pattern
I was speaking of IFs per class, this is IFs per method. But I agree,
too much logic per method is definitely a smell to examine.
d) Fear of Adding Classes is a nasty antipattern. In general, you cannot
have too many classes.
I heartly agree!
I said:
Andrew was musing about replacing all conditional with
polymorphism when he pondered if
Is it because we can't or don't want too?
Well we can, but I wasn't speaking about
a 'maybe we could add a group of classes to eliminate this
complex logic' kind of discussion. I had brought it up as an example of
a rule that is useful to apply as much as possible and probably more
than many designers choose to, but impossible to apply all the time.
For me that is okay, rules that work 95% of the time are great rules of
thumb. I didn't bring it up because I didn't like eliminating
logic by adding classes in lots of fun cases.
I'm glad you came back and reminded readers of the problem
of too few classes. I hope no one would use the observation
that all conditionals could be eliminated or hidden in one
place but we really don't want to eliminate all as an excuse
not to add a class.
The number
of classes should never influence a design decision, not even a bit.
I imagine you are thinking of a particular range of values, while
I was speaking of a theoretical end, well beyond some complex, clean
and understanable number. Sorry for the confusion.
The difference between a final and constant (practical example)
http://qa.jtiger.org/GetQAndA.action?qids=13
Wow, Tony, I think you are talking about something else. The
OP got us talking about modifying objects passed in/out and
Andrew and I got off on lots of immutables and now we are discussing the
tension between various rules of thumb or possibly something else.
I don't know about you, but I get the impression we'd actually agree
on most ways to apply such rules as:
- mutating a passed in objects
- reducing a complex or mearly long set of returns in a method.
- reducing complex conditional logic
- generating extra classes to add clarity etc.
I'm ready for a new thread, for I don't know what point
Tony nor Andrew is now going for in this thread and I think we've
addressed the OP.
-Paul