my dog learned polymorphism
The moose likes Beginning Java and the fly likes Quick Method Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Quick Method Question" Watch "Quick Method Question" New topic

Quick Method Question

Steve Rodgers

Joined: Jul 03, 2003
Posts: 21
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?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
Steve Rodgers

Joined: Jul 03, 2003
Posts: 21
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.
I agree. Here's the link:
subject: Quick Method Question
It's not a secret anymore!