Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DGDK.NET - Class within class

Author
Message
Dark Inferno Studios
18
Years of Service
User Offline
Joined: 7th Nov 2006
Location: United Kingdom
Posted: 21st Nov 2006 20:15
Hi,
How do you make a class within class, like Class1.Class2, without instancing Class2, like:
James Bondo
18
Years of Service
User Offline
Joined: 12th Nov 2006
Location: Denmark
Posted: 21st Nov 2006 20:47
Im not sure what you mean. So heres my interpretation:

Class1


Class2


Your main class


Proud member of The Unforgiven Warriors
http://www.tuwguild.com
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 21st Nov 2006 21:46
class1 would already have to have instanced class2

when you instance class1 as an object in your main code, class2 (obj2) will be shown in the dot syntax

Dim obj1 as new class1
obj1.obj2.whatever_property = whatever_val

I did this same thing in my backgammon project.

Think of bgPostNode as class1, bgChipNode as class2
bgChipNode is just a bunch of properties
bgPostNode has some props, a few methods, and a Generic.Dictionary collection object. When a bgPostNode is instanced, its constructor (public sub new() in vb.net) it creates 15 new bgChipNodes and adds them to its internal collection, and since its using Generics its using strongly typed collections of my class type, not vanilla "As Object" (type safe )

Now in main code the one new postnode object lets me reference thru to any of the 15 chipnodes and all of their properties/methods/events (if available). The chipnode class could be defined as Friend instead of public to hide it from the main code, but the main code had a couple of points where I needed an accessor object of the chipnode type, so chipnodes, although almost always accessed thru its parent postnode, was defined as Public so main code could use it if need be.

Now to take this concept one step further, I dont just instance one bgPostNode, but 24 of them (the 24 posts in backgammon + 2 for bumping and 2 for chips off the board). I again use a generics.dictionary in the main code to hold the 28 postnodes, and their 15 chipnodes (each) so thats a total of 480 chipnode objects.

...sorry to ramble
hoped that helped in some way.

Mudbug
18
Years of Service
User Offline
Joined: 2nd Nov 2006
Location: Rome, GA USA
Posted: 22nd Nov 2006 02:39
Here is my interpretation of what you asked:

Here is the class and the nested class:



And here is use of these classes from main console application:



-MudBug

Login to post a reply

Server time is: 2024-11-19 09:30:59
Your offset time is: 2024-11-19 09:30:59