I currently have a class
i've decided I need a second type of
Foo where I want to test out a significantly different implementation. It will no doubt share some functionality with
Foo so I'll need to create a Abstract Class parent for both of them.
At the end of the process I want to have:
AbstractFoo: an abstract class
FooBoo: functionaly identical to the original
FooBar: the new subclass of AbstractFoo I've created.
There are two ways I could go about this:
Copy Paste, then Refactor
- Create a copy of
Foo, and name it
FooBarwith the new implementation
FooBoo, move methods that are the same between them into a abstract class
AbstractFoo, which both inherit from
Refactor, then Implement
- Consider what methods are not related to the part of the implementation that
FooBazare going to be different in. Move these to
FooBazand reimplement all the methods that remain within
Which is to be preferred? *Is there another method?*
Last time I had to do this, it was because the I decided that
Foo had 2 different modes, that was determined by a boolean passed into the constructor.
This time (on a different class), it is because I want to try out using a different engine underneath that might be faster.
I want to keep
FooBoo around because it has a subclass that I think will be much harder to implement for
FooBaz, and I also want to be able to check that in the end they behave the same.