473,320 Members | 1,887 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,320 software developers and data experts.

Inherits VS Implements....what's the difference?

Jim
What is the difference between using Inherits and Implements? I think I get
it, but I want to be sure.....
Dec 21 '05 #1
8 23029
December 21, 2005

Basically, Inherits allows you to have your class get a COPY of the parent
class's methods and code (and therefore you don't have to write it
again).... Basically, Implements is the same as Inherits, although there is
no CODE behind the methods. Therefore, you get the 'shell' of the methods,
but you have to write the code inside the methods, and therefore a custom
implementation.... Also, Implements is only used with Interfaces...

--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://71.39.42.23/

"Jim" <re***@groups.please> wrote in message
news:H7******************@bignews6.bellsouth.net.. .
What is the difference between using Inherits and Implements? I think I
get it, but I want to be sure.....

Dec 21 '05 #2
"Jim" <re***@groups.please> schrieb:
What is the difference between using Inherits and Implements? I think I
get it, but I want to be sure.....


Classes can inherit from other classes, and they can implement interfaces.
Implementing an interface means that the developer adds the behavior of the
methods defined in an interface the class implements to the class. By
inheriting implementations of the base class are made implicitly available
to the derived class. Interfaces can typically inherit from other
interfaces.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 21 '05 #3
Inherits will include the implementation of each method/property of the
inherited class.

Implements will only give you the same interface. You need to provide your
own implementation.

The harder question is when to use each one. Here's my opinion:

You want to inherit a class when your new class is strongly related to the
class you want to inherit. Your new class should just be a specialized
version of the base class you are inheriting. These relationships are
typical described by "Is a". For example: Secretary is an Employee. In
this case all Employees have common atrtributes such as SS number, Office
Number, ... A Secretary will only have different responsibilities and
therefore can inherit most all of the Employee class.

The reason you would want to implement a class is because the relationship
can be linked through a common interface but the implementation of this
interface will be different for every class. For example: Bears are
animals. In this example, a Bear is really not a specialized version of
Animal because each animal is very different and don't really share any
common functions. But they all need to eat, sleep, ... It's just that the
do it very differently. Since every animal is so different you can't really.
Therefore inheritance is not correct. Instead all animals will implement
the Animal interface. So, they can be looked at as both a Bear and an
Animal. If you want to know the fancy OO word for this it is called
polymorphism.

Of course you could take this further and say that a Bear is a Mammal and
mix the whole thing up. In this case you would have Bear inheriting Mammal
which implements the Animal Interface. (OOD is fun!)

"Jim" wrote:
What is the difference between using Inherits and Implements? I think I get
it, but I want to be sure.....

Dec 21 '05 #4
Jim
Beautiful description!

Thanks so much!

"Joseph Bittman MVP MCSD" <Ry*********@msn.com> wrote in message
news:ug**************@TK2MSFTNGP09.phx.gbl...
December 21, 2005

Basically, Inherits allows you to have your class get a COPY of the
parent class's methods and code (and therefore you don't have to write it
again).... Basically, Implements is the same as Inherits, although there
is no CODE behind the methods. Therefore, you get the 'shell' of the
methods, but you have to write the code inside the methods, and therefore
a custom implementation.... Also, Implements is only used with
Interfaces...

--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://71.39.42.23/

"Jim" <re***@groups.please> wrote in message
news:H7******************@bignews6.bellsouth.net.. .
What is the difference between using Inherits and Implements? I think I
get it, but I want to be sure.....


Dec 21 '05 #5
Jim
That makes things clearer for me.

Thanks!!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Jim" <re***@groups.please> schrieb:
What is the difference between using Inherits and Implements? I think I
get it, but I want to be sure.....


Classes can inherit from other classes, and they can implement interfaces.
Implementing an interface means that the developer adds the behavior of
the methods defined in an interface the class implements to the class. By
inheriting implementations of the base class are made implicitly available
to the derived class. Interfaces can typically inherit from other
interfaces.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 21 '05 #6
Jim
Another great explanation!

Thanks!
"TrtnJohn" <Tr******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Inherits will include the implementation of each method/property of the
inherited class.

Implements will only give you the same interface. You need to provide
your
own implementation.

The harder question is when to use each one. Here's my opinion:

You want to inherit a class when your new class is strongly related to the
class you want to inherit. Your new class should just be a specialized
version of the base class you are inheriting. These relationships are
typical described by "Is a". For example: Secretary is an Employee. In
this case all Employees have common atrtributes such as SS number, Office
Number, ... A Secretary will only have different responsibilities and
therefore can inherit most all of the Employee class.

The reason you would want to implement a class is because the relationship
can be linked through a common interface but the implementation of this
interface will be different for every class. For example: Bears are
animals. In this example, a Bear is really not a specialized version of
Animal because each animal is very different and don't really share any
common functions. But they all need to eat, sleep, ... It's just that
the
do it very differently. Since every animal is so different you can't
really.
Therefore inheritance is not correct. Instead all animals will implement
the Animal interface. So, they can be looked at as both a Bear and an
Animal. If you want to know the fancy OO word for this it is called
polymorphism.

Of course you could take this further and say that a Bear is a Mammal and
mix the whole thing up. In this case you would have Bear inheriting
Mammal
which implements the Animal Interface. (OOD is fun!)

"Jim" wrote:
What is the difference between using Inherits and Implements? I think I
get
it, but I want to be sure.....

Dec 21 '05 #7
I INHERIT DNA from my parents and ancestors: Each bit of DNA in my cells
is a copy (of a copy of a copy ...) of a piece of DNA that was an actual
part of my father or my mother's body.

I IMPLEMENT my job function: there is a manual I am handed by my employer
which tells me what to do, but it's up to me to actually do it.
Dec 21 '05 #8
Jim,

I made a little sample for that.

http://www.vb-tips.com/default.aspx?...2-257c27db8f7a

I hope this helps,

Cor
Dec 22 '05 #9

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

Similar topics

1
by: Nick | last post by:
I am writing an application that uses a custom class which inherits DictionaryBase so that I can add items with an associated key. When I try to serialize the object though, I get the following...
2
by: Jet Leung | last post by:
Hi all, In VB.net if I want to inherits a Class and implement a interface I can wrote like this: Class A Inherits CObject Implements IObject ..... End Class
7
by: Chris Lane | last post by:
Hi, I have the following class declaration and the ide is giving the following errors. Interface 'System.Web.UI.IPostBackDataHandler' is already implemented by base class...
1
by: Mike9900 | last post by:
I would like to return an object which inherits an interface. A web service instantiate a class that inherits that interface and returns that object. But I get error when referencing the web...
7
by: Bart_D | last post by:
Hi, Can anybody explain me what's the difference between for example: imports system.data implements ICallbackEventHandler inherits System.Web.UI.Page Thanks Bart
1
by: Arpan | last post by:
What's the difference between "Imports" & "Inherits"? For e.g. both the codes below work without any errors: Imports System Imports System.Data Imports System.Web.UI Namespace Constructors...
4
by: Tom P. | last post by:
What would the difference be between the following two: public class Foo : IList<string> { .... } public class Foo : List<string>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.