• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Interface and Abstract class ........

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method where as in case of an abstract class if you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change
plz Xplain me for above Qn
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.


ok, and what is your question?
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may create a new interface with additional new abstract method so your concrete class don't need to change.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's why I tend to create interfaces and abstract classes in pairs. For the most part, you can extend the abstract class. You only need to use the interface if you must extend some other class. This way I get the best of both worlds.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually sometimes *want* to know all the classes that might need to implement a new method. So even when using the interface - abstract class pair, I'll first go through all the compile time errors in the concrete classes, implement the method where the default behaviour will not suffice, and *then* add the default behaviour to the abstract class.

It's one of the times where, when used with care, you can use compile time errors to help you find code you need to adjust.
 
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic