473,473 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Class with In a Class?

In vb.net what is the benefit of having a class within a class?

If anyone can pass the knowledge it would greatly be appreciated.
Nov 20 '05 #1
3 864
It's a very broad question but possible reasons include:
A property of a class being another class
Using inherits to extend behaviour - eg create a base class 'Individual'
that handles Name and Addess functionality

This can then be inherited to a customer class, a contact, a patient etc

Have alook at the topic Visual Basic Language Concepts - Inheritance in
MSDN for more
"JoseM" <jo***********@hotmail.com> wrote in message
news:d9**************************@posting.google.c om...
In vb.net what is the benefit of having a class within a class?

If anyone can pass the knowledge it would greatly be appreciated.

Nov 20 '05 #2
* jo***********@hotmail.com (JoseM) scripsit:
In vb.net what is the benefit of having a class within a class?

If anyone can pass the knowledge it would greatly be appreciated.


In addition to the other reply: Have a look at the .NET framework class
library to see in which situations nested classes make sense.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
JoseM,
As the others suggest, can you be a little more specific in what you are
asking?
Do you mean a nested class?

Public Class Class1
Private Class Class2
End Class
End Class

Having Class2 nested inside of Class1 is a form of Encapsulation, I would
use this when Class2 is an implementation detail of Class1 and Class2 is not
needed anyplace else, such as the Node class of a LinkedList class, where
the Node represents the "links" in the LinkedList.

Something like (greatly simplified):

Public Class LinkedList

Private Class Node
Public Data As Object
Public Next As Node
Public Previous As Node
End Class

Private m_head As Node
Private m_tail As Node

Public Sub Add(data As Object)
Dim node As New Node
node.Data = data
node.Next = m_head
node.Previous = Nothing
m_head = node
End Sub
End Class

The Node class is nested inside of LinkedList as it is not useful outside of
the context of a LinkedList. Having Node private to LinkedList ensures that
only LinkedList is able to use the Node class.

Hope this helps
Jay
"JoseM" <jo***********@hotmail.com> wrote in message
news:d9**************************@posting.google.c om...
In vb.net what is the benefit of having a class within a class?

If anyone can pass the knowledge it would greatly be appreciated.

Nov 20 '05 #4

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.