Abstract vs interface
Which should be used and when?
Just saw that if all abstract methods, then it becomes interface.
Still not got any good example that can justify the usage of abstract, interface and which is better.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Aug 5, 2009, 1:24 AM
Roei BarPosted Aug 5, 2009, 1:14 AM
Kirtan PatelPosted Aug 5, 2009, 1:09 AM
provide body for these methods once they implement it.
Abstract provides both methods with and without body. Adding new methods in abstract class in middle of development life cycle won't break existing sub classes unless these methods are declared as must override. If there are frequent addition of new methods properties and so on. one should use abstract..
Adding new methods to the interface will force users to go through each and
every sub class that implemented that interface and call these methods.
So its always preferred to use abstract over interface because of this limitation.
Whereas on the other hand interface can fill gap of multiple inheritance. One can
implement from more than one interface. Not same with Abstract. One can inherit
from only one abstract class.
Happy Coding :)