[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Interface and Abstract Class

Posted on 2013-05-16
1
Medium Priority
?
241 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:
Meir Rivkin 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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