Lesson 1: Namespace Fundamentals
The purpose of this lesson is to introduce the namespace and object oriented programming (OOP) concepts. I find this chapter confusing and aggressively asserting a Microsoft-centric view of OOP. I assume that I would not have so much trouble with this lesson when I am not aware of the famous achievements of Sun Microsystems!
- "Namespaces are a way of organizing code. They provide protection from conflicting names, sometimes called namespace collisions."
Namespaces are imported with the using keyword in C# and the Imports keyword in VB.NET. References to namespaces outside of the current VS.NET project depends on the Project > Add Reference command.
- "Visual Studio projects store code in classes and modules."
The OOP concept of definition is in the use of the class keyword in C# and the Class/Module...End Class/Module blocks in VB.NET.
- "Visual Basic .NET and Visual C# use six key concepts for working with modules and classes."
These concepts are Definition, Access, Inheritance, Constructors and destructors, Delegates, and Abstract classes and interfaces. The opinion here is that two of these concepts, Inheritance and Abstract classes and interfaces, can be rolled up under polymorphism as suggested by the MSDN article "Polymorphism in Components" at:
http://msdn.microsoft.com/library/en-us/vbcon
/html/vbconImplementingInterfacesInComponents.asp
- "[In Visual C#] There are five levels of access to classes, modules and their members: public, protected, internal, protected internal and private."
Correspondingly, in VB.NET we have: Public, Protected, Friend, Protected Friend and Private.
It may be useful to associate the "protection" of members with inheritance, that the very presence of the protected keyword implies a design featuring inheritance.
- "[In Visual C#] Classes can inherit members from base classes and override or overload members of the inherited class."
The author's definition of inheritance for VB.NET deliberately does not use the term "base class" evidently because of its use of the Module... VB.NET inheritance has been awarded the feature called "shadowing" while C# appears to be coming up short. However, the C# Programmer's Reference covers the topic of the new modifier here:
http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_10_2_2.asp
The author's code sample on page 107 uses the new modifier and is doing the equivalent of VB.NET's shadowing. The "Overview of the Inheritance Keywords" table on pages 102--103 finally shows this equivalence explicitly.
- "[In Visual C#]...Constructor methods have the same name as their class, and destructor methods use the class name preceded by a tilde (~)."
Correspondingly, in VB.NET we have the New() and Finalize() methods.
- "[In Visual C#] The delegate keyword provides a safe way to call methods by their address rather than by their name. This is the .NET equivalent of a callback."
Correspondingly, in VB.NET we have the Delegate statement.
- "You can't inherit from more than one base class in a single derived class definition."
Another way to say this is that "multiple inheritance" is not supported by the .NET platform. When the author introduces this term there is also the first hint to the stereotypical VB6 programmer that there is another world out there beyond the realm of Microsoft using terms like multiple inheritance. I find that addressing this stereotypical audience in the book is more of an obstacle than not.
- "A derived class inherits the members of its base class. If the derived class defines a member with the same signature, the derived member overrides the base member. A member's signature includes its name, parameter list, parameter types, and return type."
A derived member can overload or shadow the base member without regard to the base member's declaration. In C#, when a base member is declared as virtual (or Overridable in VB.NET), a derived member can override this base base member.
- "An abstract class is a class that defines an interface for derived classes. An abstract class is essentially a contract saying that all classes based on it will provide certain methods and properties."
For more information, see MSDN article "Recommendations for Abstract Classes vs. Interfaces" here:
http://msdn.microsoft.com/library/en-us/vbcon
/html/vbconAbstractClassesVersusInterfaces.asp
- "Delegates are types used to invoke one or more methods where the actual method invoked is determined at run time."
For more information, see MSDN article "An Introduction to Delegates" here:
http://msdn.microsoft.com/msdnmag/issues/01/04/net/default.aspx
- "Visual Basic .NET provides two ways to use a delegate."
The first pattern uses WithEvents and Handles keywords, which makes VB.NET backwards compatible with VB6. The second pattern uses AddHandler and RemoveHandler statements, which makes VB.NET syntax similar to C# delegate patterns.
- "Interfaces are similar to abstract classes... The difference is that interfaces don't provide any implementation of class members... The key here is that all items defined in the interface must exist in any class that implements the interface. If you omit any member, you get an error when you compile the code."