From: Lew on
Rhino wrote:
>>> Is it bad design for any reason for methods in one class to call
>>> other methods in the same class to do some of their work for them?
>>> I'm pretty sure the answer is no but this is just a sanity check to
>>> make sure I'm not forgetting an important factor.

Arne Vajhøj wrote:
>> It is very bad design never to do it.
>>
>> Calling other methods is the standard way to keep the size of methods
>> down (and thereby improving readability).

Rhino wrote:
> Good! I will do so whenever I can, in good conscience!

Better would be to do so whenever it makes sense. Just because you can is not
a valid engineering justification.

--
Lew
From: Lew on
Rhino wrote:
> ... getLocales(), which returns a TreeMap, and then displays the
> contents of the TreeMap on the console.

It's mostly a good idea to declare variables as an interface type rather than
a concrete type. The rule of thumb is that you declare the variable with the
loosest possible type that has the behavioral contract you need.

Thus, you probably want 'getLocales()' to return a 'SortedMap', as someone
suggested in another thread, unless there's something specific about 'TreeMap'
in particular that requires you use only that type or a subtype thereof.

--
Lew
From: Arne Vajhøj on
On 21-05-2010 19:23, Rhino wrote:
> Arne Vajh�j<arne(a)vajhoej.dk> wrote in
> news:4bf6ee28$0$285$14726298(a)news.sunsite.dk:
>> On 21-05-2010 16:20, Rhino wrote:
>>> Is it bad design for any reason for methods in one class to call
>>> other methods in the same class to do some of their work for them?
>>> I'm pretty sure the answer is no but this is just a sanity check to
>>> make sure I'm not forgetting an important factor.
>>
>> It is very bad design never to do it.
>>
>> Calling other methods is the standard way to keep the size of methods
>> down (and thereby improving readability).
>
> Good! I will do so whenever I can, in good conscience!

Pick a good balance.

500 lines methods are not good.

But no methods > 3 lines is not good either.

Arne
From: Robert Klemme on
On 22.05.2010 01:57, Lew wrote:
> Rhino wrote:
>> ... getLocales(), which returns a TreeMap, and then displays the
>> contents of the TreeMap on the console.
>
> It's mostly a good idea to declare variables as an interface type rather
> than a concrete type. The rule of thumb is that you declare the variable
> with the loosest possible type that has the behavioral contract you need.
>
> Thus, you probably want 'getLocales()' to return a 'SortedMap', as
> someone suggested in another thread, unless there's something specific
> about 'TreeMap' in particular that requires you use only that type or a
> subtype thereof.

Adding to that: Depending on what DisplayLocales does it might be
reasonable to give it an argument of Iterable<Locale> so it can display
Locale instances regardless from where they were obtained. If
displayLocales() does extensive formatting of Locale instances for
display, you might even cut your methods differently. If, on the
contrary you just need this one way to obtain and display Locales it is
most reasonable to have it like OP did it.

It's not that there is the one and only reasonable solution to
distribution of functionality across methods but it always depends on
circumstance. Often this means that during the life time of an
application things need to be refactored to adjust to changed requirements.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
From: Eric Sosman on
On 5/21/2010 7:22 PM, Rhino wrote:
> Eric Sosman<esosman(a)ieee-dot-org.invalid> wrote in
> news:ht6uo6$flf$1(a)news.eternal-september.org:
>> [...]
>> Get a copy of "Effective Java" by Joshua Bloch, and read what
>> he says about designing for inheritance. Read the rest of the book,
>> too: It's good for the soul.
>>
> I've heard a lot of good things about that book. Unfortunately, money is
> tight right now so it's going to have to wait a bit. But I will try to
> get it - and read it - when circumstances permit.....

Excellent. Shouldn't take more than two or three years to
scrape together the thirty bucks.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid