Avatar of aspnetDottech
aspnetDottech

asked on 

Interface and abstract clarification

real time example of interface and abstract class and when to use interface or abstract class
ASP.NETVisual C++.NETC#

Avatar of undefined
Last Comment
prajapati84
Avatar of prajapati84
prajapati84
Flag of India image

I hope you will get what you want:

An interface defines a contract - something anything implementing that interface MUST do. It can NEVER specify how that something is done.

An abstract class is similar in that it also defines what must be done by a class implementing it, but it can have some implementation as well. In many cases, these implementations are considered as default implementations and can be overridden in derived classes. If derived classes don't ovverride it, than the abstract class's implementation is used. If you want something that can be used in all derived classes, you can put it in the base class.

Although they both provide a contract of sorts, they are different. A class can implement many intrerfaces, but can only have a single base class. Using an interface, when you publish it, it's pretty much sealed. Any change in the interface will require you to change every implementation of that interface. If you publish the interface to many developers, that's not really an option. Using an abstract base class, you can add some behaviour / data to the base class and if done properly, it won't need any changes in code for classes deriving from the base class. All existing code will exist to work. But this takes away the single base class a class can derive from and enforces the "evil" of inheritance.

Think of an interface in terms of behaviour and abstract base classes in terms of implementation.

Reference articles:
http://forums.asp.net/t/1523088.aspx
http://www.codeproject.com/Questions/43970/Real-world-examples-of-abstract-classes-and-interf.aspx
Avatar of aspnetDottech
aspnetDottech

ASKER



Thanks, i got to know the details of interface and abstract. however, I would like to know the real time projects usage apart from animals, vechile and general examples available on internet.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

>>I would like to know the real time projects usage apart from animals, vechile and general examples available on internet.


Does it really help if I said XXX corporation uses both techniques in their app YYY  (which could involve vehicles unfortunately so any details would be rejected by your clause).  The main point is that both do have their uses.
Avatar of prajapati84
prajapati84
Flag of India image

Avatar of prajapati84
prajapati84
Flag of India image

The above example use the employee class usage.
Avatar of aspnetDottech
aspnetDottech

ASKER

can you please help me with small expample here only
ASKER CERTIFIED SOLUTION
Avatar of prajapati84
prajapati84
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo