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
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.
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.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, the permaculture playing cards