简体   繁体   中英

why namespace types should not depend on nested namespaces types?

In .Net naming guidelines ( http://msdn.microsoft.com/en-us/library/893ke618(v=vs.71).aspx ) there is this statement:

"A nested namespace should have a dependency on types in the containing namespace. For example, the classes in the System.Web.UI.Design depend on the classes in System.Web.UI. However, the classes in System.Web.UI do not depend on the classes in System.Web.UI.Design."

I would like to know: why?

Because it makes sense when you think about it.

Let me explain with a small example:

A knife-blade for example needs a handle for it to be a "knife".

But a handle doesn't need a knife-blade to be a handle, correct?

using KitchenSet;
using KitchenSet.Knives; // This is where your knives (what uses Blades) would live.
using KitchenSet.Knives.Blades; // The actual blades. 

This is a wise rule, because classes defined in the System.Web.UI namespace are visible for classes defined in the System.Web.UI.Design, but classes defined in the System.Web.UI.Design namespace are not visible for classes defined in the System.Web.UI namespace. It is necessary to add a using statement (Imports in VB.NET) in the latter case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM