This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to add new method?

 
Liz Brown
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic