I have the following code:
MyVersion6 myClass = returnMyClass();
// about 50 lines of code that do the following:
// do some logic with fields of myClass
// create and return another class using some fields of myClass
Now I have to support version 7 and I can return it in the returnMyClass() method.
What's the most elegant way to implement the remaining 50 lines? In this case, MyVersion6 and MyVersion7 support exactly the same methods but I don't want to do it like
if ( myClass instanceOf MyVersion6 )
do the 50 lines using (MyVersion6) myClass
else if ( ( myClass instanceOf MyVersion7 )
do the exact same 50 lines using (MyVersion7) myClass
Any ideas?