How to refactor duplicated code without using helper classes?

From: Sylvain (redhotsly_at_hotmail.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 13:46:07 -0500

What is the correct way to refactor duplicated code?

Suppose you have Class A and Class B. Some code is duplicated in Class A and
Class B. If there is a base class for these classes or if it is justified to
extract a base class for Class A and Class B then I can move the code there.

However, if Class A and Class B do not have a base class and if it is not
justified to extract a base class, the simple way to resolve the problem is
to move the code in a public static method of a public helper class. But I
don't like helper classes and helper methods; they are too close to function
libraries and too far from OO.

In our project we now have at least 10 helpers classes with dozens of static
methods. I would like to get rid of them but I am not sure how to do so.

Thanks

Syl



Relevant Pages

  • Re: OO development question...
    ... I am so new to OO, I am not sure what you mean by "helper" ... What kind of a base class would I inherit from - ... property to house the 1-M relationship it is in with the 3rd class... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to refactor duplicated code without using helper classes?
    ... >extract a base class for Class A and Class B then I can move the code there. ... >to move the code in a public static method of a public helper class. ... >libraries and too far from OO. ... Object Mentor Inc. | unclebob @ objectmentor. ...
    (comp.object)
  • Re: How to refactor duplicated code without using helper classes?
    ... > extract a base class for Class A and Class B then I can move the code ... > to move the code in a public static method of a public helper class. ... and B don't have a common base yet they share a common purpose, ... statics as a staging area. ...
    (comp.object)
  • Reading values from NameObjectCollectionBase
    ... I can extract the keys that have been used to add items to the collections ... using the Keysproperty which is implemented in the base class, ... As the class appears by definition to hold matching pairs of names ...
    (microsoft.public.dotnet.languages.vb)