Jump to content

Namespace in .NET 2005 ?


nobitavn94

Recommended Posts

Well, I'm a Delphi 2006 User and seems you are too...I used to think namespaces were nested objects, later on I learned they aren'tThis is a little chart of what namespaces really are...The unit uImgResize.pas is a file,it's an image resizer that works over JPEG formatwhere you have the following text inside------------------------------------unit uImgResizeinterfacetype TMyResizeTool= class ... end;implementationend.------------------------------------So let's say you have another Image Resizer, but this one works for BMP formats...they both have the same "look"(class and procedure names)So, you could as well call them JPEG_RESIZER and BMP_RESIZER, that would work...but a better way to have so many units files is to use the NAMESPACESso let's name them files as JPEG.Resizer and BMP.Resizer (it is extremelly recommended not to do it manually or through the explorer, use your Delphi or whatever program you have)so, now we are at the page where we have this uses clausesuses JPEG.Resizer, BMP.Resizernow let's declare a variable for eachvar bmp_rsz: TMyResizeTool; jpg_rsz: TMyResizeTool;oops, now we have a problem....it's ok, in this case we say the fullname of the classvar bmp_rsz: BMP.Resizer.TMyResizeTool; jpg_rsz: JPEG.Resizer.TMyResizeTool;easily corrected.Let's get some more problems to fix...procedure TWebForm1.SomeMethod;var bmp_rsz: BMP.Resizer.TMyResizeTool; jpg_rsz: JPEG.Resizer.TMyResizeTool;begin bmp_rsz := TMyResizeTool.Create; jpg_rsz := TMyResizeTool.Create;end;This would perfectly work without the namespaces, but it will throw an error, or even worse... "you won't be sure!"Once more, it's piece of cake...procedure TWebForm1.SomeMethod;var bmp_rsz: JPEG.Resizer.TMyResizeTool; jpg_rsz: BMP.Resizer.TMyResizeTool;begin bmp_rsz := BMP.Resizer.TMyResizeTool.Create; jpg_rsz := JPEG.Resizer.TMyResizeTool.Create;end;---------------------In a nutshell, NameSpaces aren't nested classes,they are just a fine way to organize your units,and believe me, use them! even if you use them,you won't have to write it fully all the time,IE if you want to make a textbox at runtime...it's nice you saytxt_01: System.Web.UI.TextBox;but you can just say txt_01: TextBox;-----------------------Answering you real question...WebSites aren't made of NameSpaces,NameSpaces are Separators for Units,that take effect on the classes it has inside.Hope I helped. :)

Link to comment
Share on other sites

txt_01: System.Web.UI.TextBox;but you can just say txt_01: TextBox;
As long as you have referenced System.Web.UI by using:using System.Web.UIOnce you have referenced that namespace, you can use any available class within that namespace.If, on the other hand, you have created a "Website" in Visual Studio 2005, most of your classes and VB code will go in the App_Code directory. These classes are available to the entire website without needing to use namespaces.However, like the previous poster, I would recommend getting into the habit of using namespaces.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...