473,230 Members | 1,572 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,230 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 2016
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...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.