C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Again on Abstract classes and Interfaces


Posted Date: 06 Sep 2006      Total Responses: 8

Posted By: priya menon       Member Level: Silver     Points: 2


Hi,

Once again on same topic, well after hearing and reading all about Abstract classes and interfaces, its time for reality check, how many of you out there were in a situtaion where you had to decide that you have to use an interface OR an abstract class?

-------------------------------------------------------------------------------
--------------------------------------------------------------------------------


1. is it better to have interfaces as first hand tool of designing classes? or can an interface act as blueprint for a class? ( Y/N)

2. if i have to implement all methods of an interface, when i inherit an interface in a class, and in case i use an interface for many classes in my project, and there is a need that i need to add or remove some methods from and interface, and now .. this is a big problem as all my classes useig this interface will be problem, So interface is bad ??? so how can abstract class help me in this

3.so HELL interfaces are good to implement Naming conventions thorugh out yoru project (Y/N)


Please come up with good reasoning rather than just diffrences.

well some real time cases will close this matter of discussion.

Note: i have read as much of threads as possible on this forum about the topic under scanner.

I have read somewhere "Interface first and code next" does it stand good enough?

i know most of you are busy out there ..take your own time.


Thanks in advance.
Priya




Responses

Author: Kr. Hemendra Singh Shaktawat    06 Sep 2006Member Level: GoldRating:     Points: 2
Hi,

Its on need basis than the choice.

Abstract Class is a fullfedge class with most common functionality and property so you can not make an object of an Abstract class. Example Human is Abstract
and Ram is derived from Human.

Ok Now Interface is a class like implementation that has only function bodies. We use Interface to achieve multiple inheritance as multiple inheritance is not directally supported in C#.

Hope this helps.

Good Luck

Hemendra Singh Shaktawat

Mindfire Solutions
www.mindfiresolutions.com


Author: tapan dalai    07 Sep 2006Member Level: SilverRating:     Points: 2


1) yes interface act as blueprint for a class.
2)go through my document bellow...u can get aneswar.
3)yes

Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components.

If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.
If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.
If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.

If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members

tapan dalai
tapan.dalai@gmail.com
cell 9880383372



Author: DotNetGuts (DNG)    11 Sep 2006Member Level: DiamondRating:     Points: 2
Refer it for better understanding
1) http://www.dotnetspider.com/kb/Article2293.aspx
2) http://www.dotnetspider.com/kb/Article2306.aspx


Author: Mrunal Brahmbhatt    21 Nov 2007Member Level: BronzeRating:     Points: 2
Both Interface and Abstract Class are different from each other do not mix up.

Situation where functionality may add/remove "Abstract Class" is best solution.

Eg. Creating Base Classes,Creating Base for your project where functionality may be added or remove or can be override if needed.Mostly common task are move to base class and if required than can be overrided.


Situation where we have fix requirement "Interface" is best solution.

Eg. Plugin .Where Pluging can be loaded dynamically and executes its functionality.
Thus that Plugin must follow or implement certain functionality.

Its concept of Plug and Adapter.



Author: asdf    08 Aug 2008Member Level: SilverRating:     Points: 0

• Abstract Class
Cannot be instantiated.
Must be inherited and its methods should be overridden.
It have some concreate methods.
Access modifiers allowed.


• Interface
Have definition of a method not implementation. (implement through class)
Multiple inheritance possible through Interface only
Only Public Access modifier only allowed. Defaultly Public
No need of virtual overridden.
It’s used for to define a set of properties, methods and events.





Author: Bunty    18 Sep 2008Member Level: DiamondRating:     Points: 4
Hi,


Interfaces are similar to abstract classes.However,interface represent the highest level of abstraction in object-oriented programming.This is because all the methods in an interface are abstract and do not have implementation.In contrast,the abstract classes that are created using Abstract keyword might contain a method that has a body.

Regards
S.S.Bajoria


Author: Bunty    23 Sep 2008Member Level: DiamondRating:     Points: 6
Hi,

Following are the difference between abstract and interface,

1>Abstract class having method declaration as well as method method definition whereas interface having method declaration only.

2>Abstract class are known as partial abstract class whereas interface is known as fully abstract class.

3>Abstract class features we have to inherit to the child class whereas interface features we have to implement in the child classes.

4>Abstract class support access specifiers whereas interface doesn't support access specifiers.

5>Abstract class have normal variable as well as constant variable whereas interface have only constant variables.

6>We can write constructor in abstract class whereas we can't write constructor in interface.

Regards
S.S.Bajoria



Author: Meetu Choudhary    23 Oct 2008Member Level: GoldRating:     Points: 6
Hi,

Interface

A standard way of calling routines and passing data structures. For example, the interface between two layers of code might be expressed in terms of routines that pass and return a particular data structure. Linux's VFS is a good example of an interface.

An interface in the programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signatures and constant declarations (variable declarations which are declared to be both static and final). An interface may never contain method definitions.

As interfaces are implicitly abstract, they cannot be directly instantiated. Object references may be specified to be of an interface type; in which case they must either be null, or be bound to an object which implements the interface.

The keyword implements is used to declare that a given class implements an interface. A class which implements an interface must either implement all methods in the interface, or be an abstract class.

One benefit of using interfaces is that they simulate multiple inheritance.


for more information please visit

http://en.wikipedia.org/wiki/Interface_(Java)

==
Thanks and Regards
Meetu Choudhary



Post Reply
You must Sign In to post a response.
Next : How will we call javascript or vbscript in coding ? give an example with coding?
Previous : can we use c++ code in .net?
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use