?
Solved

Interface and Abstract Class

Posted on 2013-05-16
1
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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