I’m having a small problem with inheritance with a hierarchy of classes
The example is
Class Class
Private m_classB as Class
Class Class
End Clas
End Clas
Class Class
Inherits Class
End Clas
How do I add properties to ClassB within ClassC 7 2423
In this case, ClassB is a nested class of ClassA. So what to do depends on
what desired effect you want.
If what you're looking for is a way to access m_classB from ClassC, just
make it Protected instead of Private in ClassA
If you're trying to extend ClassB from ClassC, that's not going to happen.
The best you can hope for is creating another nested class in ClassC that
inherits from ClassB.
-Rob Teixeira [MVP]
"Ryan Shaw" <an*******@disc ussions.microso ft.com> wrote in message
news:ED******** *************** ***********@mic rosoft.com... I'm having a small problem with inheritance with a hierarchy of classes. The example is:
Class Class A Private m_classB as ClassB
Class ClassB End Class End Class
Class ClassC Inherits ClassA End Class
How do I add properties to ClassB within ClassC?
In this case, ClassB is a nested class of ClassA. So what to do depends on
what desired effect you want.
If what you're looking for is a way to access m_classB from ClassC, just
make it Protected instead of Private in ClassA
If you're trying to extend ClassB from ClassC, that's not going to happen.
The best you can hope for is creating another nested class in ClassC that
inherits from ClassB.
-Rob Teixeira [MVP]
"Ryan Shaw" <an*******@disc ussions.microso ft.com> wrote in message
news:ED******** *************** ***********@mic rosoft.com... I'm having a small problem with inheritance with a hierarchy of classes. The example is:
Class Class A Private m_classB as ClassB
Class ClassB End Class End Class
Class ClassC Inherits ClassA End Class
How do I add properties to ClassB within ClassC?
Hi Ryan,
In my opinion is m_classB an object instanced from Class B
I get the idea that you try to make multi inherriting in a clever way.
As far as I can see in your example is Class B from the same order as Class
A.
And multi inherriting is not possible in VB.net.
I hope this helps
Cor
Hi Ryan,
In my opinion is m_classB an object instanced from Class B
I get the idea that you try to make multi inherriting in a clever way.
As far as I can see in your example is Class B from the same order as Class
A.
And multi inherriting is not possible in VB.net.
I hope this helps
Cor
Well, I'm still a little confused if what I'm trying to do is considered multi threading or posible. Here is a more detailed example: In my real issue, I have the public members as properties. When I use ClassB, the second public member does not show up
Public Class Class
Public nestedClassB As ClassB = New Class
Public Class Class
Public Inner1 As Strin
End Clas
End Clas
Public Class Class
Inherits Class
Public Shadows Class Class
Inherits ClassA.Class
Public Inner2 As Strin
End Clas
End Class
"Ryan Shaw" <an*******@disc ussions.microso ft.com> schrieb Well, I'm still a little confused if what I'm trying to do is considered multi threading or posible. Here is a more detailed example: In my real issue, I have the public members as properties. When I use ClassB, the second public member does not show up.
Which ClassB do you use: ClassA.ClassB or ClassC.ClassB? How do you use
ClassB? Where does the member not show up? Public Class ClassA Public nestedClassB As ClassB = New ClassB
Public Class ClassB Public Inner1 As String End Class End Class
Public Class ClassC Inherits ClassA
Public Shadows Class ClassB Inherits ClassA.ClassB Public Inner2 As String End Class End Class
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Ryan,
You don't really need to use Shadows here, its adding to your confusion! Public Shadows Class ClassB
I would simply make it ClassD
The first problem you are having is when you create a ClassA object it
automatically creates a ClassA.ClassB object, you need to let ClassA &
ClassC decide what member to create. I would use constructors for this.
ClassA should define a protected constructor that allows you to set the
nested variable, both ClassA & ClassC should define public default
constructors that call the protected constructor with an instance of the
correct nested type.
Try something like:
Public Class ClassA
Public ReadOnly nestedClassB As ClassB
Public Sub New()
MyClass.New(New ClassB)
End Sub
Protected Sub New(ByVal nested As ClassB)
nestedClassB = nested
End Sub
Public Class ClassB
Public Inner1 As String
End Class
End Class
Public Class ClassC
Inherits ClassA
Public Sub New()
MyBase.New(New ClassD)
End Sub
Public Class ClassD
Inherits ClassA.ClassB
Public Inner2 As String
End Class
End Class
The second problem that you are having is that ClassA has defined a public
variable of type ClassA.ClassB. ClassA.ClassB does not have a Inner2 field,
ClassC.ClassD has the Inner2 field. You will need to cast the nestedClassB
variable to ClassC.ClassD to see Inner2. However casting is not polmorphic.
If you need to access Inner2 from ClassA a lot, you may want to add an
overridable property of ClasssB that ClassD can implement
Public Class ClassB
Public Inner1 As String
Public Overridable Property Inner2 As String
Get
' I would either throw an exception or return a
reasonable default
' depending on the desired results.
Throw New NotImplementedE xception
End
Set(value As String)
' I would either throw an exception or return a
reasonable default
Throw New NotImplementedE xception
End Set
End Property
End Class
Public Class ClassD : Inherits ClassA.ClassB
Public Inner1 As String
Private m_inner2 As String
Public Overrides Property Inner2 As String
Get
Return m_inner2
End
Set(value As String)
m_inner2 = value
End Set
End Property
End Class
Hope this helps
Jay
"Ryan Shaw" <an*******@disc ussions.microso ft.com> wrote in message
news:A8******** *************** ***********@mic rosoft.com... Well, I'm still a little confused if what I'm trying to do is considered
multi threading or posible. Here is a more detailed example: In my real
issue, I have the public members as properties. When I use ClassB, the
second public member does not show up. Public Class ClassA Public nestedClassB As ClassB = New ClassB
Public Class ClassB Public Inner1 As String End Class End Class
Public Class ClassC Inherits ClassA
Public Shadows Class ClassB Inherits ClassA.ClassB Public Inner2 As String End Class End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephane Ninin |
last post by:
Hello all,
I am trying to play with nested class in a script I am making,
and I am not sure I really understand how they work.
Here is some code:
__all__ =
|
by: Paul Morrow |
last post by:
I'm hoping that someone can explain why I get the following exception.
When I execute the code...
######################################
class Parent(object):
class Foo(object):
baz = 'hello from Parent.Foo'
class Child(Parent):
#Foo.baz = 'hello from Child.Foo'
|
by: KInd |
last post by:
Hello All,
When is nested class more preferable that Inheritance ? I think with proper
inheritance and friend class concept we can get the same flexibility as nested
classes
Any comments ..
Best Regards
KInd
--
|
by: Markus Ernst |
last post by:
Hello
In a content administration tool I call classes from inside classes in order
to separate the admin functions from the display-only functions:
class book
{
var $title;
var $author;
var $adminfunctions;
|
by: Luis Diego Fallas |
last post by:
Hi everyone ,
I'm having a problem when trying to compile code that contains the
following pattern:
using System;
public class A {
public class B : Inn.C { }
| |
by: Christopher Ireland |
last post by:
Hi --
I'm trying to find an example of a nested class implemented within the .NET
Framework itself but without much success. I don't suppose that anybody
knows of such an example off the top of their head, do they?
Many thanks!
--
Best Regards,
|
by: C# Learner |
last post by:
Is it not possible to declare a nested class in a seperate file from
its "parent" class -- i.e. in a similar way to the idea of spreading
namespaces over more than one file?
|
by: Martin Skou |
last post by:
I'm experimenting with using Python for a small web interface, using
Mark Hammond's nice win32 extensions.
I use a small class hierarchy which uses inheritance and nested classes.
Here are a small extract of the code:
class page:
def __init__(self):
|
by: stephen.diverdi |
last post by:
Can anyone lend a hand on getting this particular template
specialization working? I've been trying to compile with g++ 4.1 and
VS 2005.
//------------------------------------------------------------------
// my regular glass
class A { };
// my templated class
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |