473,480 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Confusion over namespaces

Hello,

I have a solution with two projects.

One of the projects is called MyProj with a root namespace called
MyProj.Obj.

The single source (vb) file for MyProj has a class called Obj. There is no
enclosing namespace, i.e. the class declaration is at the top of the file.

The second project is called MyProjUser and has a reference to MyProj.

The single source file for MyProjUser has the following imports statement:

Imports MyProj.Obj

Then I have a statement further down in MyProjUser like this:

Dim o as Obj

But the compiler doesn't like it. It says that Obj isn't defined.

The compiler is happier when I either have this Imports statement:

Imports MyProj.Obj.Obj

or with this statement in code:

Dim o as Obj.Obj.

What's happening here? I thought that once I imported the namespace (in this
case MyObj.Obj), then all classes in that namespace (including Obj) should
be usable without further qualification.

Or is the fact that part of the namespace and the class name are the same
(i.e. Obj) causing confusion?

TIA for any answers.

--
Akin

aknak at aksoto dot idps dot co dot uk
May 16 '06 #1
1 1136
Think of namespaces and objects as files and directories on your harddrive

your namespace is akin to c:\myproj\obj
and inside that you have created a file called obj.

in order to access your file, you must specify its full path
c:\myproj\obj\obj

a way that I use namespaces is to break the assemblies into thought areas,
i.e

mycompany.myproject.

data libraries would go into mycompany.myproject.datalib
graphic libraries into mycompany.myproject..graphics
UI components into mycompany.myproject and
mycompany.myproject.customcontrols.

Additionally, when I create an assembly with a sepreate namespace it is
generally because the project itself can potentially be reused by other
assemblies without modification, otherwise, the code would all live with the
executing assembly.

for example

Our encryption library is mycompany.encryption
Our xml, adodbo, and csv wrappers live in mycompany.data
Our generic containers such as sorted bindinglist(of T) live in
mycompany.generics
Our login UI components, security model all live in mycompany.security and
mycompany.security.ui

Finally, we then reference these libraries when designing an application

Accounting package base namespace is mycompany.accpac

imports mycompany.accpac
imports gencol = mycompany.generics

UI components import
imports mycompany.accpac.business
imports mycompany.accpac.UI

Business Objects import
imports mycompany.accpac.data
imports db = mycompany.data
imports enc = mycompany.encryption
imports sec = mycompany.security

add system references (i.e. xml, data, text, collections) as appropriate

"Epetruk" <no****@blackhole.com> wrote in message
news:4c*************@individual.net...
Hello,

I have a solution with two projects.

One of the projects is called MyProj with a root namespace called
MyProj.Obj.

The single source (vb) file for MyProj has a class called Obj. There is no
enclosing namespace, i.e. the class declaration is at the top of the file.

The second project is called MyProjUser and has a reference to MyProj.

The single source file for MyProjUser has the following imports statement:

Imports MyProj.Obj

Then I have a statement further down in MyProjUser like this:

Dim o as Obj

But the compiler doesn't like it. It says that Obj isn't defined.

The compiler is happier when I either have this Imports statement:

Imports MyProj.Obj.Obj

or with this statement in code:

Dim o as Obj.Obj.

What's happening here? I thought that once I imported the namespace (in
this
case MyObj.Obj), then all classes in that namespace (including Obj) should
be usable without further qualification.

Or is the fact that part of the namespace and the class name are the same
(i.e. Obj) causing confusion?

TIA for any answers.

--
Akin

aknak at aksoto dot idps dot co dot uk

May 17 '06 #2

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

Similar topics

18
3007
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
11
1737
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
9
1311
by: Buz Waitz | last post by:
I'm a newbie. I've created a datalayer class which I creatively called sqlAccess and placed in a namespace I just as creatively called MyDomain.DataAccessLayer. (Well now, I didn't actually use...
4
2645
by: Ranginald | last post by:
Sorry for the simple question but thanks in advance: My goal is to create reusale code for a web app in C#. I have written the code already as a windows app but here is where I am confused: ...
6
2244
by: vivekian | last post by:
Hi, I am not sure if this is a relevant topic here, anyways, When using the std namespace is it a good practice to .. put this right at the beginning using namespace std ;
2
2021
by: shaun roe | last post by:
I'm trying to follow the recommendations for svg writing at http://jwatt.org/svg/authoring/ and I am generating my svg with xslt. I had some problem with namespaces, and although I think I solved...
8
1053
by: tshad | last post by:
Using VS 2008, I have a project that uses the dll from another project. The Namespace is MyFunctions, with a class of DbObject. The beginning of the code is: ***************************...
0
7037
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
6904
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...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6886
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
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.