From: pjb@... (Pascal J. Bourguignon) Date: 2008-03-11T18:34:55+09:00 Subject: Re: Which is better -- method option or multiple methods? Trans writes: > In the case of limited options, like the following example, which is > better? > > class String > > def align(direction. spacing) > case direction > when :left > ... > when :right > ... > when :center > ... > end > end > > OR > > def align_left(spacing) > ... > end > > def align_right(spacing) > ... > end > > def align_center(spacing) > ... > end > > Thanks, > T. > OR: def align(direction. spacing) insertSpaces( 4 * @@mapDirectionsToOffset[direction] ); end That is, you could choose between one form or the other depending on whether the method is continuous or discontinuous on that argument. If you have to write a case, then use several methods. If you can define a single formula, then use a single method. Becareful in spite of my formulation, this choice should be done from an abstract point of view, is the essence of this parameter to influence the method in a discontinuous way or a continuous way? Because we're talking here of the interface, and this interface should speak of the essence of things, not of their implementation details. -- __Pascal Bourguignon__