473,324 Members | 2,166 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,324 software developers and data experts.

Help with Inheritance

This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one. Each
class has some varibles that need to be reset from time to time, so I have
created a method call "Clear" that does that. So my question is when using
"Clear" in an instance of class two, the clear method in Class one does not
get called, is there some way of excucting both "Clear" Methods in a single
call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel
pretty foolish when someone points it out, but it sure has me stumped at the
moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i
Nov 20 '05 #1
12 1230
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call to
the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one. Each class has some varibles that need to be reset from time to time, so I have
created a method call "Clear" that does that. So my question is when using "Clear" in an instance of class two, the clear method in Class one does not get called, is there some way of excucting both "Clear" Methods in a single call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel
pretty foolish when someone points it out, but it sure has me stumped at the moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i

Nov 20 '05 #2
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call to
the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one. Each class has some varibles that need to be reset from time to time, so I have
created a method call "Clear" that does that. So my question is when using "Clear" in an instance of class two, the clear method in Class one does not get called, is there some way of excucting both "Clear" Methods in a single call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel
pretty foolish when someone points it out, but it sure has me stumped at the moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i

Nov 20 '05 #3
What about calling it from the "child class"?
Thanks.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message
news:rU***************@news04.bloor.is.net.cable.r ogers.com...
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call to the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one.

Each
class has some varibles that need to be reset from time to time, so I have created a method call "Clear" that does that. So my question is when

using
"Clear" in an instance of class two, the clear method in Class one does

not
get called, is there some way of excucting both "Clear" Methods in a

single
call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel pretty foolish when someone points it out, but it sure has me stumped at

the
moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING

THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i


Nov 20 '05 #4
What about calling it from the "child class"?
Thanks.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message
news:rU***************@news04.bloor.is.net.cable.r ogers.com...
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call to the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one.

Each
class has some varibles that need to be reset from time to time, so I have created a method call "Clear" that does that. So my question is when

using
"Clear" in an instance of class two, the clear method in Class one does

not
get called, is there some way of excucting both "Clear" Methods in a

single
call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel pretty foolish when someone points it out, but it sure has me stumped at

the
moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING

THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i


Nov 20 '05 #5
I think thats w Lloyd Sheen meanth

cl1
public sub clear()
'code
end sub

cl2 : cl1
public sub clear()
MyBase.Clear()
'code
end sub

hope it helps

eric

"D Miller" <de**********@yahoo.com> wrote in message
news:MD*****************@newsread1.news.pas.earthl ink.net...
What about calling it from the "child class"?
Thanks.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message news:rU***************@news04.bloor.is.net.cable.r ogers.com...
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call

to
the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one.

Each
class has some varibles that need to be reset from time to time, so I have created a method call "Clear" that does that. So my question is when

using
"Clear" in an instance of class two, the clear method in Class one
does not
get called, is there some way of excucting both "Clear" Methods in a

single
call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel pretty foolish when someone points it out, but it sure has me stumped

at the
moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING

THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i



Nov 20 '05 #6
I think thats w Lloyd Sheen meanth

cl1
public sub clear()
'code
end sub

cl2 : cl1
public sub clear()
MyBase.Clear()
'code
end sub

hope it helps

eric

"D Miller" <de**********@yahoo.com> wrote in message
news:MD*****************@newsread1.news.pas.earthl ink.net...
What about calling it from the "child class"?
Thanks.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message news:rU***************@news04.bloor.is.net.cable.r ogers.com...
If I understand you have the two classes both with Clear methods. If you
call the Class2.Clear simply (depending on the language used) add a call

to
the Clear in the parent class.

For VB.NET the syntax is MyBase.Clear()
For C# it is base.Clear();

Lloyd Sheen

"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net...
This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one.

Each
class has some varibles that need to be reset from time to time, so I have created a method call "Clear" that does that. So my question is when

using
"Clear" in an instance of class two, the clear method in Class one
does not
get called, is there some way of excucting both "Clear" Methods in a

single
call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel pretty foolish when someone points it out, but it sure has me stumped

at the
moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING

THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i



Nov 20 '05 #7
"D Miller" <de**********@yahoo.com> schrieb
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
HAVING THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
mybase.Clear
end sub


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
"D Miller" <de**********@yahoo.com> schrieb
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
HAVING THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
mybase.Clear
end sub


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
D Miller,
In addition to the other's comments I would recommend NOT using Shadows
here, I would recommend making Clear Overridable.

Making Clear Overridable will allow Class2.Clear to execute if you put a
Class2 object in a Class1 variable. If you left Class2.Clear Shadows, only
Class1.Clear would be called...
Public Class Class1 Public Overridable Sub Clear
mPrice = 0
mQty =0
end sub end class Public Class Class2
inherits Class1 Public Overrides Sub Clear MyBase.Clear() mInvoice = 0
end sub end class
Then you will be able to do:

Dim c As Class1() = New Class2()
c.Clear()

And Class2.Clear will be called, which will call Class1.Clear.

I tend to reserve Shadows for upgrade situations where the base method is
introduced that is not compatible with a derived method & a couple of other
specialized cases...

Hope this helps
Jay
"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net... This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one. Each class has some varibles that need to be reset from time to time, so I have
created a method call "Clear" that does that. So my question is when using "Clear" in an instance of class two, the clear method in Class one does not get called, is there some way of excucting both "Clear" Methods in a single call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel
pretty foolish when someone points it out, but it sure has me stumped at the moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i

Nov 20 '05 #10
D Miller,
In addition to the other's comments I would recommend NOT using Shadows
here, I would recommend making Clear Overridable.

Making Clear Overridable will allow Class2.Clear to execute if you put a
Class2 object in a Class1 variable. If you left Class2.Clear Shadows, only
Class1.Clear would be called...
Public Class Class1 Public Overridable Sub Clear
mPrice = 0
mQty =0
end sub end class Public Class Class2
inherits Class1 Public Overrides Sub Clear MyBase.Clear() mInvoice = 0
end sub end class
Then you will be able to do:

Dim c As Class1() = New Class2()
c.Clear()

And Class2.Clear will be called, which will call Class1.Clear.

I tend to reserve Shadows for upgrade situations where the base method is
introduced that is not compatible with a derived method & a couple of other
specialized cases...

Hope this helps
Jay
"D Miller" <de**********@yahoo.com> wrote in message
news:QL****************@newsread1.news.pas.earthli nk.net... This may be a basic question, but it sure has me stumpted..
I have two classes, Class1 and Class2. Class 2 inherits class one. Each class has some varibles that need to be reset from time to time, so I have
created a method call "Clear" that does that. So my question is when using "Clear" in an instance of class two, the clear method in Class one does not get called, is there some way of excucting both "Clear" Methods in a single call... See the code below for what I mean...

There must be a simple way of doing this, and I suspect I'm going to feel
pretty foolish when someone points it out, but it sure has me stumped at the moment...

Thank you,
David
Public Class1
dim mQty as integer
dim mPrice as double
Public Sub Clear
mPrice = 0
mQty =0
end sub

Public Property Price as Double
Get
return mPrice
end get
Set(ByVal Value as Double)
mPrice = Value
end set
end property

Public Property Qty as Integer
Get
return mQty
end get
Set(ByVal Value as Integer)
mQty = Value
end set
end property
end class

Public Class2
inherits Class1
dim mInvoice as integer
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0
end sub
Public Property Invoice as Integer
Get
return mInvoice
end get
Set(ByVal Value as Integer)
mInvoice = Value
end set
end property
end class

i

Nov 20 '05 #11
I figured it would be something simple, thanks!

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"D Miller" <de**********@yahoo.com> schrieb
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
HAVING THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0


mybase.Clear
end sub


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #12
I figured it would be something simple, thanks!

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"D Miller" <de**********@yahoo.com> schrieb
Public Shadows Sub Clear
' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
HAVING THIS
METHOD RUN THE CLEAR METHOD OF CLASS1?
mInvoice = 0


mybase.Clear
end sub


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #13

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

Similar topics

6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
3
by: majid | last post by:
How can i write classes with multiple inheritance
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
2
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any...
23
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
3
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is...
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.