From: Robert Klemme Date: 2008-03-11T06:19:55+09:00 Subject: Re: Which is better -- method option or multiple methods? On 10.03.2008 20:50, Paul Mckibbin wrote: > Robert Klemme wrote: >> On 10.03.2008 20:09, Paul Mckibbin wrote: >>> Method options are better if you ever want to extend it. >> How is that? How can a single method that switches over one or more >> arguments to decide what to do be easier extended? What if you detect >> that the new or one of the algorithms needs an additional argument which >> is not needed by other algorithms? >> >>> I personally >>> would have both in library code, but would be inclined to keep the >>> multiple method code private to keep the interface clean. >> A clean interface in my world is one where one method does exactly one >> thing - and not multiple things. If all those algorithms share some >> common code this should go into another method that all of them use. >> Much cleaner, more maintainable and easier to understand. Just think >> about a method's documentation, that can do 5 different things vs. five >> methods with their own documentation. > > You are quite right. My code showed what I intended, but I garbled the To be honest, I just briefly looked at the code because it looked too similar to the original. :-) But even then I would have asked how your explanation and code fit together. :-) > explanation. Single method with switches should be private for > implementation, and I tend to use that to make the code DRYer. Multiple > methods for the exposed interface. > Normally I'd start with multiple (separate) methods and create the > private function when there was an obvious need to refactor and > opportunity to make the code DRYer. Yep, same here. Kind regards robert