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

Implementing a sub class

Hi - I'm trying to implement what a seems to be a very simple concept, but I
can't figure out how exactly it is supposed to be done.

I want to define a class that has sub classes, so I'll explain in a very
simplified manner:

The main class will be called "MyAppClass". This class will have two
methods - "GenericMethod1" and "GenericMethod2". Then I want to have two
sub classes inside MyAppClass called "Section1Class" and "Section2Class".
Section1Class has a method called "DoSection1Work", and Section2Class has a
method called "DoSection2Work"

Then, user of MyAppClass would use it in the following way:

Dim obj as new MyAppClass

obj.GenericMethod1()
obj.Section2Class.DoSection2Work()

Please tell me how I implement this "sub class" idea.

Thanks,
Brian
Apr 9 '07 #1
6 6550
"Brian Patrick" <bp*********@hotmail.comwrote in news:#sJGdPseHHA.1388
@TK2MSFTNGP05.phx.gbl:
Please tell me how I implement this "sub class" idea.
Create a property in your main class which exposes the sub class.
Apr 9 '07 #2
On Apr 9, 1:26 pm, Spam Catcher <spamhoney...@rogers.comwrote:
"Brian Patrick" <bpatrick...@hotmail.comwrote in news:#sJGdPseHHA.1388
@TK2MSFTNGP05.phx.gbl:
Please tell me how I implement this "sub class" idea.

Create a property in your main class which exposes the sub class.
You can nest classes together like so....

Public Class SectionClass1

...class methods and properties

Public Class SectionClass2

Public Sub DoSomething()
............
End Sub

End Class

End Class

DoSomething method can be called by

SectionClass1.SectionClass2.DoSomething()

Apr 9 '07 #3
This implementation does not work - when I try it, the DoSomething() method
is not accessible.

"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 9, 1:26 pm, Spam Catcher <spamhoney...@rogers.comwrote:
>"Brian Patrick" <bpatrick...@hotmail.comwrote in news:#sJGdPseHHA.1388
@TK2MSFTNGP05.phx.gbl:
Please tell me how I implement this "sub class" idea.

Create a property in your main class which exposes the sub class.

You can nest classes together like so....

Public Class SectionClass1

...class methods and properties

Public Class SectionClass2

Public Sub DoSomething()
............
End Sub

End Class

End Class

DoSomething method can be called by

SectionClass1.SectionClass2.DoSomething()

Apr 9 '07 #4
This is the way I'm doing it now, and it works - however, how do I keep the
sub class from being instantiated from the outside? I only want the class
creatable via the parent class. Using the "Protected" keyword doesn't work.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Brian Patrick" <bp*********@hotmail.comwrote in news:#sJGdPseHHA.1388
@TK2MSFTNGP05.phx.gbl:
>Please tell me how I implement this "sub class" idea.

Create a property in your main class which exposes the sub class.

Apr 9 '07 #5
On Apr 9, 1:46 pm, "Brian Patrick" <bpatrick...@hotmail.comwrote:
This implementation does not work - when I try it, the DoSomething() method
is not accessible.

"Charlie Brown" <cbr...@duclaw.comwrote in message

news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 9, 1:26 pm, Spam Catcher <spamhoney...@rogers.comwrote:
"Brian Patrick" <bpatrick...@hotmail.comwrote in news:#sJGdPseHHA.1388
@TK2MSFTNGP05.phx.gbl:
Please tell me how I implement this "sub class" idea.
Create a property in your main class which exposes the sub class.
You can nest classes together like so....
Public Class SectionClass1
...class methods and properties
Public Class SectionClass2
Public Sub DoSomething()
............
End Sub
End Class
End Class
DoSomething method can be called by
SectionClass1.SectionClass2.DoSomething()
You need to instantiate SectionClass2 before you can access
DoSomething(). Alternatively you could use a singleton implementation
(single instance self-instantiating classes) on both of the nested
classes. Here's Jon Skeet's article on a few different patterns (in
C#) http://www.yoda.arachsys.com/csharp/singleton.html

Thanks,

Seth Rowe

Apr 9 '07 #6
Sub class, as in:
Acheron, Astute, Delta, Dolphin, Echo, Golf, Harushio, Los Angeles,
Ming, Ohio, Oscar, Oyashio, Romeo, Triomphant, Type 206A, Typhoon,
Vanguard, Whiskey, Yuan -- other?

;-)
Apr 11 '07 #7

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

Similar topics

7
by: Doran_Dermot | last post by:
Hi All, I've seen lots of code in which the attributes of a class are accessed and modified using two separate methods. For example: class Problems: def __init__( self, refNum ):...
0
by: nmichaud | last post by:
I am having a problem implementing some methods of a python class in C. The class is defined in python, but I would like to rewrite some methods in c. Here is an example of what I want to do: ...
1
by: Devon | last post by:
Hi, I'm just getting my feet wet with C# and need some help with interface implementation. I want to create a collection of various objects that implement a certain interface (i.e. IMyInterface)....
2
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base...
1
by: Hans De Schrijver | last post by:
I'm pretty new to C# development, so here's a newby question regarding accessibility: Scenario: class1 contains some basic properies and methods class2 inherits from class1 and adds some...
3
by: Richard | last post by:
Hi, I'm new to C# and are having difficultly implementing an interface class. Basically I want to define an interface class, then inherit it. I want some of the methods to be public, and...
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...
0
by: hans | last post by:
Hallo! I want to be able to make my application configurable for which implementation of XmlReader should be used. App.config: <?xml version="1.0" encoding="utf-8" ?> <configuration>...
10
by: Smokey Grindle | last post by:
i want to inherit the list view class, but in the inherited class, hide the Header style property and the view property (basically its a detailed list with always clickable headers) how do I keep...
0
by: neroliang | last post by:
PyLucene Homepage: pylucene.osafoundation.org 1.Quotas from PyLucene: """ Technically, the PyLucene programmer is not providing an 'extension' but a Python implementation of a set of methods...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.