| Author |
where to add new method?
|
Liz Brown
Ranch Hand
Joined: Oct 22, 2002
Posts: 112
|
|
I have an interface say A with method1(). There is 1 abstract class say B which implements this interface A. The abstract class has implemented the method1 with 2 more methods, methodE, methodD. If I want to add 1more methodH which will do methodE, MethodD and another new one methodZ, what can I do in this case? Should I make a new method in interface or abstract class?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
Consider what will happen when you upcast. That is, if you instantiate an object that extends the abstract class, and then upcast its reference to the interface type, would it make sense for the new method to be available there?
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
If you put it on your interface then all implementations of the interface will have to implement it, not just the abstract class you have today. If you put it on your abstract class then any references that are typed to the interface cannot call it. Does that matter? Avoid this really ugly situation:
|
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
|
 |
 |
|
|
subject: where to add new method?
|
|
|