
07-10-2012, 09:00 AM
|
 |
Senior Contributor
* Expert *
|
|
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,272
|
|
|
I'll try and explain what's going on as best I can, but it is kinda complicated and might take a lot of text to explain.
It's ultimately part of a stock control system. The part I'm dealing with here is the picking. Going from very simple to more complicated. The most simple, i.e. the base class's, implementation does not bother with quantities of parts. It is just cross reference. So when the user enters a part they want to pick it just shows the user the list of locations known to the system and they choose the one they want.
The next iteration of the system introduces quantities. This changes the picking because after entering a part they want to pick they have to say how many they want to pick. The user no longer chooses what location they want to pick from, the system does that for them (based on FIFO). So this second iteration overrides when a part number has been entered and goes about getting the quantity and working out the location before going back to the base class's methods for the rest of the pick.
The third iteration introduces users (for transaction logging, i.e. traceability) as well as being able to gather other information (such as a Transaction reference, just another form of traceability for the users). So it overrides bits of the second iteration to do its own things before returning to the base to record stuff.
What's happened now is that a customer kind of needs this third iteration to work without quantities. So, I need the functionality of the first iteration but with the extra bits that have been added for this third iteration.
So I saw that I had 3 choices. One was to go entering loads of code into the third iteration to try and cope with this, but the problem there is that I'd have to do loads of testing to make sure I hadn't broke the original functionality. That's something I like about inheritance. I don't have to touch what is already there so I know it's still going to work.
The other two choices are where I inherit from. I could inherit the first iteration's class for this but that means I'd have to add the extra functionality that the third iteration does (like the users, the transaction ref, etc.) and that seems like more work than is required.
So the third choice is to inherit the third iteration's but make it call the first iteration's method at the point where the second overrides it (doubt that makes sense).
Moving the code in the first iteration into a different method for the fourth iteration to call has worked, I just wasn't too sure if there was a better way.
|
__________________
There are no computers in heaven!
Last edited by DrPunk; 07-10-2012 at 09:06 AM.
|