Solved

Interface and Abstract Class

Posted on 2013-05-16
1
235 Views
Last Modified: 2013-08-10
Hi,

If I am asked to make a choice between an abstract class and the interface, which one should i opt for. what are the things which i have to consider before choosing one among them.

Thanks in advance
Rajeeva
0
Comment
Question by:rajeeva_nagaraj
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39171131
the most substantial difference between abstract and interface is that interface is declarative only while abstract can contain implementation.
this is a good post to start with:
http://www.codeproject.com/Articles/11155/Abstract-Class-versus-Interface

in general, u choose abstract when u have shared functionality among your concrete objects.
for instance, let's say you have interface class Shape and concrete classes Triangle, Square etc, which derive from Shape base class.
now, and u want to add SaveToFile functionality.
instead of having the same implantation to all concrete classes, you could change the Shape class to abstract and implement SaveToFile there.
in relate to my previous example, when passing the shape objects as interface and not as abstract class, u can hide shared functionality which are internal.
for instance, the SaveToFile can be declared in the IShape interface.
assume u want to have common function to calculate area of shape but not to expose it in the interface.
the Shape abstract class is the place to add this function.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question