469,328 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

How do I do MyBase.MyBase?

I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
MyBase?

In Short what is the VB equivalent of "::"?

Example:

Class Component
Inherits Hashtable

Public Shadows Sub Add()
'Extra Add stuf for this component
End Sub
End Class

~~~~~~~~~~~~~~~
Class BetterComponent
Inherits Component

Public Shadows Sub Add()
'How do I get to the Hashtable.Add and skip the "Extra Component" stuff??
End Sub
End Class
Nov 21 '05 #1
9 8677
haven't thought of that...have you tried:

if not typeof mybase is [type of object you want to deal with] then return
dim whatever as [type of object you want to deal with] = mybase
'do whatever you want to do from here

btw, the base of a base is not a "parent".

hth,

steve
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:_D******************@newssvr33.news.prodigy.c om...
|I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
| MyBase?
|
| In Short what is the VB equivalent of "::"?
|
| Example:
|
| Class Component
| Inherits Hashtable
|
| Public Shadows Sub Add()
| 'Extra Add stuf for this component
| End Sub
| End Class
|
| ~~~~~~~~~~~~~~~
| Class BetterComponent
| Inherits Component
|
| Public Shadows Sub Add()
| 'How do I get to the Hashtable.Add and skip the "Extra Component"
stuff??
| End Sub
| End Class
|
|
Nov 21 '05 #2
Yes, but I don't want to simply return I want to go up the inheritance tree
to the parent class (in code it's not necessarily a parent, in class
hierarchy it is).

Henry Padilla
"steve" <a@b.com> wrote in message
news:10*************@corp.supernews.com...
haven't thought of that...have you tried:

if not typeof mybase is [type of object you want to deal with] then return
dim whatever as [type of object you want to deal with] = mybase
'do whatever you want to do from here

btw, the base of a base is not a "parent".

hth,

steve
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:_D******************@newssvr33.news.prodigy.c om...
|I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
| MyBase?
|
| In Short what is the VB equivalent of "::"?
|
| Example:
|
| Class Component
| Inherits Hashtable
|
| Public Shadows Sub Add()
| 'Extra Add stuf for this component
| End Sub
| End Class
|
| ~~~~~~~~~~~~~~~
| Class BetterComponent
| Inherits Component
|
| Public Shadows Sub Add()
| 'How do I get to the Hashtable.Add and skip the "Extra Component"
stuff??
| End Sub
| End Class
|
|

Nov 21 '05 #3
I don't think this is possible, though I could be wrong.

Besides, how would this work if your class inherited from object and didn't
have a 'grandparent'?

"Henry Padilla" <pa******@hotmail.com> wrote in message
news:vy******************@newssvr17.news.prodigy.c om...
Yes, but I don't want to simply return I want to go up the inheritance tree to the parent class (in code it's not necessarily a parent, in class
hierarchy it is).

Henry Padilla
"steve" <a@b.com> wrote in message
news:10*************@corp.supernews.com...
haven't thought of that...have you tried:

if not typeof mybase is [type of object you want to deal with] then return dim whatever as [type of object you want to deal with] = mybase
'do whatever you want to do from here

btw, the base of a base is not a "parent".

hth,

steve
"Henry Padilla" <pa******@hotmail.com> wrote in message
news:_D******************@newssvr33.news.prodigy.c om...
|I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of | MyBase?
|
| In Short what is the VB equivalent of "::"?
|
| Example:
|
| Class Component
| Inherits Hashtable
|
| Public Shadows Sub Add()
| 'Extra Add stuf for this component
| End Sub
| End Class
|
| ~~~~~~~~~~~~~~~
| Class BetterComponent
| Inherits Component
|
| Public Shadows Sub Add()
| 'How do I get to the Hashtable.Add and skip the "Extra Component"
stuff??
| End Sub
| End Class
|
|


Nov 21 '05 #4
ALL YOUR BASE ARE BELONG TO US!

Sorry...had to say it.

Anyway, since it looks like you are trying to do this for components you are
writing, why not just add a property to the Component class you wrote that
returns what you are looking for. If this property doesn't exist then
you'll know that you've gone as far back as you can go. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Henry Padilla" <pa******@hotmail.com> wrote in message
news:_D******************@newssvr33.news.prodigy.c om...
I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of
MyBase?

In Short what is the VB equivalent of "::"?

Example:

Class Component
Inherits Hashtable

Public Shadows Sub Add()
'Extra Add stuf for this component
End Sub
End Class

~~~~~~~~~~~~~~~
Class BetterComponent
Inherits Component

Public Shadows Sub Add()
'How do I get to the Hashtable.Add and skip the "Extra Component" stuff?? End Sub
End Class

Nov 21 '05 #5
"Henry Padilla" <pa******@hotmail.com> schrieb:
I realize that MyBase.MyBase is illegal, so how DO I get to
the Parent of MyBase?


You cannot. This could lead to unintended use of a class.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #6
so what you're saying herf, is that vb doesn't define scope and interface
access correctly...since most other oop languages do give access to
traversing underlying classes...i.e. "::" ?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:up**************@TK2MSFTNGP14.phx.gbl...
| "Henry Padilla" <pa******@hotmail.com> schrieb:
| >I realize that MyBase.MyBase is illegal, so how DO I get to
| > the Parent of MyBase?
|
| You cannot. This could lead to unintended use of a class.
|
| --
| Herfried K. Wagner [MVP]
| <URL:http://dotnet.mvps.org/>
Nov 21 '05 #7
Hi ste,

"steve" <a@b.com> schrieb:
so what you're saying herf, is that vb doesn't define scope and interface
access correctly...since most other oop languages do give access to
traversing underlying classes...i.e. "::" ?


In VB.NET, C#, and Java access is resticted to the direct base class to
prevent inconsistencies in an object's state. Consider this sample:

\\\
Public Class A
Private m_Sum As Integer

Public Overridable Sub Add(ByVal Number As Integer)
m_Sum += Number
End Sub
End Class

Public Class B
Inherits A

Private m_Checksum As Integer

Public Overrides Sub Add(ByVal Number As Integer)
MyBase.Add(Number)
m_Checksum = ...
End Sub
End Class

Public Class C
Inherits B

' Objects of type 'C' are objects of type 'B' too. 'B' guarantees
' that the checksum will be set properly. If there was a way to
' call 'A''s 'Add' method directly, the checksum set in 'B' would
' not be updated and thus the class' state would be inconsistent.
End Class
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #8
Steve,
so what you're saying herf, is that vb doesn't define scope and interface
access correctly...since most other oop languages do give access to
traversing underlying classes...i.e. "::" ? Most?

C# has the same safety net, I believe Managed C++ does also. Java does, I
don't know Smalltalk or Eiffel well enough to say, I would not be surprised
if they had the same safety net also.

Only language that I remember that allows this is C++, even there I remember
it was discouraged. I want to say one of Scott Meyers "Effective C++" books
touched on it, however I am not seeing the reference right now.
My understanding is it is enforced by the CLR itself, as knowing who your
grand base class is not really needed in OOP. You shouldn't really care or
know who your grand base class is, as your class lineage can change, both
who your inherit from & what they implement, which is why I understand
referring to specific base classes, other then your immediate parent, in C++
is frowned upon also.

My biggest concern is you might bypass code that is "Required" by the class
hierarchy, for example, if Derived class calls a GrandBase function
directly, by-passing a Base function, where the Base function is needed for
the entire hierarchy to function correctly...

IMHO: I actually see the restriction as fixing a scope & interface access
problem that older OOP languages exhibit.

Just a thought
Jay


"steve" <a@b.com> wrote in message
news:10*************@corp.supernews.com... so what you're saying herf, is that vb doesn't define scope and interface
access correctly...since most other oop languages do give access to
traversing underlying classes...i.e. "::" ?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:up**************@TK2MSFTNGP14.phx.gbl...
| "Henry Padilla" <pa******@hotmail.com> schrieb:
| >I realize that MyBase.MyBase is illegal, so how DO I get to
| > the Parent of MyBase?
|
| You cannot. This could lead to unintended use of a class.
|
| --
| Herfried K. Wagner [MVP]
| <URL:http://dotnet.mvps.org/>

Nov 21 '05 #9
Thanks! This is exactly what I needed, and why.

Tons of help.

I am going to have to take the time and implement my base class correctly to
begin with.

Henry Padilla

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u5**************@TK2MSFTNGP11.phx.gbl...
Hi ste,

"steve" <a@b.com> schrieb:
so what you're saying herf, is that vb doesn't define scope and interface access correctly...since most other oop languages do give access to
traversing underlying classes...i.e. "::" ?


In VB.NET, C#, and Java access is resticted to the direct base class to
prevent inconsistencies in an object's state. Consider this sample:

\\\
Public Class A
Private m_Sum As Integer

Public Overridable Sub Add(ByVal Number As Integer)
m_Sum += Number
End Sub
End Class

Public Class B
Inherits A

Private m_Checksum As Integer

Public Overrides Sub Add(ByVal Number As Integer)
MyBase.Add(Number)
m_Checksum = ...
End Sub
End Class

Public Class C
Inherits B

' Objects of type 'C' are objects of type 'B' too. 'B' guarantees
' that the checksum will be set properly. If there was a way to
' call 'A''s 'Add' method directly, the checksum set in 'B' would
' not be updated and thus the class' state would be inconsistent.
End Class
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.