Re: Question about removing duplication: inheritance vs static methods
From: Steve (steve_a_haigh_at_hotmail.com)
Date: 10/15/03
- Next message: Wayne Dernoncourt: "UML: extends .vs.generalize"
- Previous message: Steve: "Re: P-EAA, .NET + Domain Model"
- Next in thread: Phlip: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Phlip: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Kevin Cline: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: H. S. Lahman: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Aaron Perrin: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Daniel T.: "Re: Question about removing duplication: inheritance vs static methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 15 Oct 2003 10:49:24 +0100
On Tue, 14 Oct 2003 22:12:48 +0300, tonis
<tonis22@nosp-am.starline.ee> wrote:
>Hi!
>
>I have realized that duplication is something to avoid but it isn't
>always easy to do so. One way is to use inheritance: if two classes have
>something common extract superclass with common code(using 'Template' or
>'Strategy' pattern etc). But this sometimes introduces artificial
>coupling, subclasses become dependent from superclass which can change.
>And if subclass needs modifying programmer most know much about what
>superclass is doing, also code becomes hard to read/browse ....
If you have extraced a method to a superclass you may have identified
*real* coupling, not artificial. However you have a good point if the
super class was created only as a place to hold the common method you
may have a problem. I would only want a superclass if there was a
genuine generalization relationship.
It's really hard to answer your question without some examples of the
problem. The correct answer could be anything!
Have you read "Refactoring" by Fowler? I suspect that it may answer
your questions.
The issue of code being hard to browse is addressed by good tools
(Eclipse is free so there's no excuse!) and by good developers (not
free, but they can learn, so there's no excuse).
>
> Second way is to extract static methods and put it in util classes.
>Probably more easy to do & use but not flexible and I guess not good
>design either. Also, I have noticed that following test first
>programming combined with maxim 'Do simplest thing possible' often leads
>along that way -- producing code full of static methods.
This will probably lead to a non-OO result which will not benefit from
all the good stuff (the abstaction, polymorphism etc). It will end up
being hard to maintain and difficult for other java developers to
understand.
>
>Another question: I have extracted method but don't know where to attach
>it
Then put it back until you know where to attach it:-) As above,
without some more info it is imposible to say what the right answer
is.
~ If emailing, please use: Steve_A_Haigh
~ @
~ hotmail.com
~
- Next message: Wayne Dernoncourt: "UML: extends .vs.generalize"
- Previous message: Steve: "Re: P-EAA, .NET + Domain Model"
- Next in thread: Phlip: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Phlip: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Kevin Cline: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: H. S. Lahman: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Aaron Perrin: "Re: Question about removing duplication: inheritance vs static methods"
- Maybe reply: Daniel T.: "Re: Question about removing duplication: inheritance vs static methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|