Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 21st, 2003, 03:39 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Namespace

Hi - I am working through the example data layer in chap 11 of Prof. VB.NET - Can someone clarify, why does the writer create a namespace when he/she's only got one class in the class library. I thought the idea of creating a namespace gives you the ability to group classes together and then just use something like - imports myclasses
Any comments much appreciated!
 
Old October 21st, 2003, 08:34 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You are correct, that's one of the general intents of namespaces. You can wrap a class inside of a namespace so that you can organize classes. With VB.Net an assembly has a root namespace which defines the main namespace that everything lives in. You create classes, and they live within the root namespace. If you were to create a sub class inside of the class you'd be at the third level.

Public Class MyClass
    Public Class SubClass
    End Class
End Class

<rootnamespace>.<class>.<subclass>
MyRootNamespace.MyClass.MySubClass

Namespace MyNamespace
    Public Class MyClass
        Public Class SubClass
        End Class
    End Class
End Namespace

<rootnamespace>.<namespace>.<class>.<subclass>
MyRootNamespace.MyNamespace.MyClass.MySubClass

Peter
 
Old October 21st, 2003, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

I have not read that far into the book, but there are other reasonse for namespaces. For instance, in your data layer, lets say you want to have have a set of classes that perform similar actions. A query object for example. You may want to have namespaces like DataAccess.OracleDA, DataAccess.DB2DA, DataAccess.MsSqlServerDA all haveing a query object that is specific to the data base. This allows you to not have to worry about using the same class name (Query), but for the developer using the data access layer they know that they go to the namespace for the server they are interested in, and the object will always be called Query. Now these Query objects may all inherit from DataAccess's Query object which can not be instantiated, but is the bases for the classes that are in the sub-namespaces.

Just a thought.


John R Lick
JohnRLick@hotmail.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Two namespace contain same name nir_pankaj C# 1 February 21st, 2007 12:30 PM
Namespace ~Bean~ Classic ASP Basics 2 June 3rd, 2005 02:31 PM
namespace Ibn_Aziz C# 2 December 25th, 2003 05:41 AM
namespace within namespace Bill Crawley XML 1 December 11th, 2003 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.