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

Nested Classes

Using VS2003, VB.NET, MSDE...

I am looking at a demo program that, to my surprise, has nested classes,
such as the example below. I guess it surprised me becuase you cannot have
nested subs, and I am not sure why you would want nested classes anyway.

Is there a URL that explains the advantages to nested classes, when they
would be used, etc? What are your thoughts?

Also, if a Class has nothing before it (i.e. no Public or Private, etc.), is
it automatically public or private?

Thanks!

Bob Day

Public Class x

Public Class y

Public Sub g()

End Sub

End Class

End Class
Nov 20 '05 #1
2 2022
Nested classes and nested subs are two very different paradigms (at least in
terms of implementation). Most OOP languages allow for nested types
(classes). This allows classes to construct and use private helper classes,
which aids in enapsulation of private details that shouldn't be used/abused
elsewhere. Classes can also define private implimentations of public
interfaces this way - for example, creating a private enumerator that only
this collection class uses, where the private nested enumerator class
implements the public IEnumerator interface. The main collection class is
the only one who has true knowledge of this enumerator's details, and the
only one who can create an instance of it. The outside world only sees and
interacts with the public IEnumerator interface of the object.

-Rob Teixeira [MVP]

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Using VS2003, VB.NET, MSDE...

I am looking at a demo program that, to my surprise, has nested classes,
such as the example below. I guess it surprised me becuase you cannot have nested subs, and I am not sure why you would want nested classes anyway.

Is there a URL that explains the advantages to nested classes, when they
would be used, etc? What are your thoughts?

Also, if a Class has nothing before it (i.e. no Public or Private, etc.), is it automatically public or private?

Thanks!

Bob Day

Public Class x

Public Class y

Public Sub g()

End Sub

End Class

End Class

Nov 20 '05 #2
Bob,
In addition to Rob's comments.

Nested classes are useful for implementation details of the outer class (as
Rob suggested). For example if I were to define a LinkedList class I would
define a nested Node class that contained each link of the List.

' A single linked list.
Public Class LinkedList

Private Class Node
Public Data As Object
Public Next As Node

Public Sub New(data As Object, next As Node)
Me.Data = data
Me.Next = next
End Sub

End Class

Private m_head As Node

Public Sub Add(data As Object)
m_head = New Node(data, m_head)
End Sub

Public Readonly Property Head As Object
Get
If m_head Is Nothing Then
Return Nothing
End If
Return m_head.Data
End Get
End Property

End Class

Hope this helps
Jay

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Using VS2003, VB.NET, MSDE...

I am looking at a demo program that, to my surprise, has nested classes,
such as the example below. I guess it surprised me becuase you cannot have nested subs, and I am not sure why you would want nested classes anyway.

Is there a URL that explains the advantages to nested classes, when they
would be used, etc? What are your thoughts?

Also, if a Class has nothing before it (i.e. no Public or Private, etc.), is it automatically public or private?

Thanks!

Bob Day

Public Class x

Public Class y

Public Sub g()

End Sub

End Class

End Class

Nov 20 '05 #3

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

Similar topics

3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
3
by: Rubén Campos | last post by:
Organizing classes, types, structures, enums and whatever other entities into nested namespaces requires to include into every header and implementation file the complete path of namespaces. Let me...
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
2
by: miked | last post by:
I am architecting in a read only class for use in mapping data to a business object. The object makes strong use of nested classes and their ability to access protected fields. The downside is...
5
by: Jake K | last post by:
What purpose does nesting a class inside another class typically server? Are there conditions where this would be beneficial? Thanks a lot.
3
by: Cousson, Benoit | last post by:
I don't think so; my original email was mainly a question. I do agree that they are other ways to do what I'm trying to achieve; there are always several ways to solve an issue. Few days ago, I...
0
by: Maric Michaud | last post by:
Le Tuesday 12 August 2008 23:15:23 Calvin Spealman, vous avez écrit : I was not aware of any "nested classes are unsupported" before and didn't consider nested classes as bad practice till...
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.