This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am writing a class with a number of methods that ensure data integrity. I am going to write an interface off this class. All the methods are straight forward except that I have to write one method that currently exists in another package. 1. Do I write a new method in my current class that calls the identical method in the other package? 2. Do I just instantiate the class with the original method in my main class? See what I mean? I don't want to write 2 methods with the same logic and different names in 2 packages but I like the convenience of using the interface. Any suggestions/references?
Delegation is a common OO thing. You ask me to do some work, and rather than do it myself I find someone else to do it. When a class passes resonsibility on this way, it keeps itself cleaner and less complicated. But while this might be the perfect answer, it's not entirely clear yet that this is exactly what you're doing. What kind of responsibility does your class have that is already in another package?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 03, 2003
Stan, Rather than check data integrity within each method of a specific class, we decided to write a class and interface with all checks (after the fact of course). So I began writing the methods in a new class. Then I hit method A that was already built and used pretty extensively. 1.Should I re-write method A in my class? 2.Should I leave method A alone then write a new method in my class with the same signature and actually call method A? 3.Should I not write a new method and just instantiate the class that has method A every time I need method A? I understand (I think) what the proper solution is but I�ve hit a crossroads. Do what I know is right from an OO standpoint and risk project delays or just re-write? I went with option 2 from above. Everything can�t be perfect but I�m not happy with the solution I have chosen and wondered what some other experiences were? I think I have answered my own posting. CA