Solved

Interface and Abstract Class

Posted on 2013-05-16
1
233 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now