Developing Namespaces in VB.NET 2005
(Page 1 of 6 )
This is the second article in a series focusing on inheritance in VB.NET 2005. In this article, I shall introduce you to developing namespaces in VB.NET 2005, together with inheritance.
A downloadable file for this article is available
here.
If you are new to inheritance in Visual Basic.NET, I request that you go through my first article in this series titled “Inheritance with VB.NET 2005.” If you are very new to OOP in VB.NET, I request that you go through my first article in the series “Object Oriented Database Development Using VB.NET.”
The entire source code for this article is available in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition. I didn’t really test the solution with any other previous editions. If you have any problems in executing the solution, please post in the discussion area.
What exactly is a namespace?
Everybody knows that the fundamental unit of OOPS is a “class.” In my previous articles (as specified above), I declared, defined and explained several classes with several members in different ways.
To develop an application, you are free to declare and define any number of classes. When you are dealing with too many classes, sometimes, it may be necessary for you to categorize them in a meaningful manner. Just like you encapsulate a set of members into a class, you may need to have a “categorization of classes.”
A set of classes belonging to a particular category can be grouped into a “namespace.” It is a logical structure, which contains only classes in it. Just as a class has its own name, a namespace should also be defined with its own name (or instead, the category name of the classes!).
Did we ever use namespaces before in our previous applications/samples? Yes, but all of them were pre-defined namespaces available in the huge .NET Framework class library. The .NET Framework Class Library has a huge set of pre-defined “namespaces” with thousands of “classes” hierarchically designed.
Let us consider the following statement:
System.Console.WriteLine("Hello World!");
According to the above statement, you are trying to execute a method named “WriteLine” (which is “shared”) in the class “Console” available in the namespace “System.” When we use the statement “imports,” we are actually importing all the classes available within the respective “namespace.” Don’t forget that a “namespace” can also be nested with several other “sub-namespaces” (ex: System.Web.UI etc.).
Next: A simple example of a namespace >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee