In Live projects,where we will use Abstract class and interface classes?

Posted by Nav234 under C# on 8/23/2010 | Points: 10 | Views : 23755 | Status : [Member] | Replies : 3
Hi all

In our real live projects ,Do we need to use Abstract and interface class ?
Exactly where we will be using.Does it gives us any big advantage.?
Not only those concepts ,most of us are not worried about ,where and why
we use OOPS concepts,does it adds any advantage to our application.

So any1 can help me on this issues with examples ,what advantage it gives ?


Thanks in advance

S.Naveen...


Responses

Posted by: SurajRane on: 8/23/2010 [Member] Starter | Points: 25

Up
0
Down
each one has its own advantage.

create an interface if you want to put a contract. just say five developers are writing their classes and you want to make sure each class must contain method named Dispose(). what you will do?

write an interface IDisposable.
tell developers to inherit from this Interface.
After that you will be sure that anyone who is using these classes will get Dispose() method.

-- > Another thing to tell interfaces do not come in inheritance chain, they dont have any implementation associated with them

Abstract classes

Abstract classes as you might know do not have full implementation hence we cant create object of abstract class ( think of if it would have possible, developers might have called not implemented method using its object)

example:

put your common functionality in abstract class.







Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nav234 on: 8/27/2010 [Member] Starter | Points: 25

Up
0
Down
Thank you SurajRane,

Does any1 have any more answers.

thanks in advance



S.Naveen...

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Debmalya.Kundu82 on: 10/25/2013 [Member] Starter | Points: 25

Up
0
Down
1. If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
2. If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
3. If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.
4. If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response