473,416 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Abstract Class vs. Interface

Can somebody compare Abstract Class and Interface for me?
Thanks

Nov 15 '05 #1
3 3910
http://msdn.microsoft.com/library/de...Interfaces.asp
"New Comer" <an*******@discussions.microsoft.com> wrote in message
news:11*****************************@phx.gbl...
Can somebody compare Abstract Class and Interface for me?
Thanks

Nov 15 '05 #2
Programmer's:
Legally, you can write code in an abstract class, while you are prohibited
to do so in an interface. So a concrete implementor of an abstract class can
use the abstract class's method code(say to be called before it implements
it). However both can't be instantiated.

A slightly higher level defn:
Interfaces are contracts. They help identify common behaviours of objects.
If you see any object that implements, say inherface "IHuman", you will come
to know that it would have provided implementation for ,say, methods like
"Eat(calorificVal), Sleep(hours)" etc, although each object's implementation
might be very different. (Say IndianHuman:IHuman might throw an exception on
"Sleep(hours)" except when called on a public holiday!)

Back to programmer's:
With the above example in mind, if you want to say that a person can
implement a "Sleep(hours)" and "Eat()" in whichever way he wants, you just
give an interface. But you want all humans to get a sleep for, say, 1 hour
at a minimum(otherwise yell at the person giving him less - in other words,
throw an exception), you write an abstract class with the concrete
implementation for "Sleep()" and abstract method "Eat()". So an abstract
class helps you control certain portions out of a set of defined behaviors.

Phew....so much for a one-line Q!

HTH
Krishnan
Codito Ergo Sum
"New Comer" <an*******@discussions.microsoft.com> wrote in message
news:11*****************************@phx.gbl...
Can somebody compare Abstract Class and Interface for me?
Thanks

Nov 15 '05 #3
This may help:

http://www.geocities.com/jeff_louie/OOP/oop9.htm

Regards,
Jeff
Can somebody compare Abstract Class and Interface for me?<


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
5
by: Tony Johansson | last post by:
Hello!! Assume you have an Interface called ITest with these three method declarations. interface ITest { void foo1(); void foo2(); void foo3(); }
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.