Namespaces and Visibility

K

kele

Do sub Namespaces have visibility to parent class. ie.
I am trying to develop an application that is made up of
modules and the main module contains a variables class
that contains all the variables needed for the
application.

eg.

MainModule Namespace
Contains MainMod Class
Variables Class

MainModule.SubModule Namespace
Contains SubMod Class

MainMod class populates the variables class and is the
main entry point of the application and it also calls
methods in the SubMod Class. Can SubMod Class get access
to the Variables Class and its members.

If not how should this be designed/developed.

Thanks Kel.
 
K

Klaus H. Probst

Sure, but you either have to import them or qualify them with the full name.

Namespaces have no "visibility" issues - they're always visible and public.
What's inside them is what counts.
 
K

kele

It would still not work, because you can not have
circular dependencies so if you add the reference to the
SubModule Namespace in the MainModule you can call
methods etc in the SubModule classes. But you can not
access the Variables class from the SubModule classes.

The only way I can think of getting around this is to
have the Variables Class in a module on its own (which
doesn't make as much sence).

I just wanted to know what Microsofts best practice is
for this type of design.
 
J

Jay B. Harlow [MVP - Outlook]

Kele,
As Klaus suggested NAMESPACES do not reference each other, hence there is no
chance of a circular dependencies!

..NET is able to handle correctly if you have two types (type as in classes,
structures, interfaces) that reference each other within the same assembly.

The problem comes in when you have two Assemblies reference each other,
which can lead to circular dependencies, as the first needs to be compiled
before the second, however the second needs to be compiled before the first.

If I have a need for two assemblies referencing each other, I normally
implement the Separated Interface.

http://www.martinfowler.com/eaaCatalog/separatedInterface.html

In the SubModule, define an Interface that the MainModule implements, that
the SubModule uses. Alternatively define the Interface in a third assembly.
The MainModule is then free to reference the SubModule, while the SubModule
is not explicitly dependent on the MainModule.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top