25 Oct 2004

Is inheritance a good way to refactor?

This blog entry has a point about inheritance.
I sometimes use inheritance to refactor methods that are copy/paste in objects.
I often end up with Bar1 and Bar2 extends FooAbstract.
With method: Fish FooAbstract.fishing().

But how do I test fishing() method?

Not in FooAbstractTest since Foo is abstract...
I often put tests in Bar1 but if Bar2 changes the default behavior, I won't get a red bar!
Also I can refactor tests in a FooAbstractTest extends TestCase and make
Bar1 et Bar2 extends FooTestAbstract (but I don't like that much...)

I have to think about this a little bit more....
I may give up inheritance to refactor and use delegation instead...

No comments: