C#.
Each programming language has its own way to implement static structures. C# is a new language similar to Java and C++. If you're used to these languages, you shouldn't have any trouble getting into C# and its related OOP implementation details. On the other hand, if you're used to writing code in VB 3, 4, 5, or 6, you'll probably have a harder time getting into the full-fledged OOP world of VB.NET. Concepts such as inheritance, overloading, overriding, and namespaces are new to VB.NET, but the advantages they bring are not to be taken lightly.
In order to understand the power of OOP, consider, for example, form inheritance, a new feature of .NET that lets you create a base form that becomes the basis for creating more advanced forms. The new "derived" forms automatically inherit all the functionality contained in the base form. This design paradigm makes it easy to group common functionality and, in the process, reduce maintenance costs. When the base form is modified, the "derived" classes automatically follow suit and adopt the changes. The same concept applies to any type of object. Have a look at for more information on form inheritance.
II. What OOP Constructs Can We Expect to be Writing in VB.NET and C#?
This section outlines the following six constructs that help define the relationship between UML models and the accompanying implementation code in VB.NET code and C#. These include classes, interfaces, inheritance, overriding and overloading, aggregation, and composition as well as other associations.
Classes
In a UML static structure diagram, the class is the main element. The two other main elements are interfaces and associations. A class is said to have attributes and behaviors. An attribute is simply some piece of data that is bound to a class. Attributes are often referred to as class variables or properties. The behaviors are the actions that the class can perform. They are referred to as operations or methods (subs and functions in VB).
In OOP, classes are the actual containers for all of your coding. Classes are also held in another container called a package. Packages allow you to logically group the different classes that make up your system. You're allowed to insert a class of the same name in two different packages so that you can have, for example, the following result:
- System.Database Invoice
- System.Business.Invoice
- System.GUI.Invoice
As you can see, there are three Invoice classes, each accomplishing something different (relating to an invoice) and each contained within its own package. This would be ideal in a three-tier system. Programming languages such as C# and VB.NET implement the notion of packages through namespaces.
C# was based entirely on classes from the ground up. VB programmers have been defining classes since version 5.0. Although you were able to use classes in previous VB releases, the classes were defined only as simple units. They could not take advantage of advanced concepts such as inheritance (see below). To use a class, you usually need to create an instance of it. Each instance of a class can hold its own (different) values for attributes. The behaviors will act upon that particular set of data.
Sometimes it's necessary to share an attribute (or a behavior) over each instance. In this case it is declared as static (underlined in UML notation). To access a static attribute or behavior you do not need to create a class instance. To understand how you could use static attributes or behaviors, imagine a class named LoggedOnUser, which has a static attribute named TotalLoggedOnUsers. When such a class is created, it would increment the static attribute, and when the class is destroyed, it would decrement the attribute.The following UML diagram shows a class and its associated attributes and operations:
Here's what the code looks like in VB and C#:
In this example, Customer is the name of the class. ID, Name and Phone are attributes of the class, and getLastOrder is the name of an operation that returns an object of type Order.
Page 1 of 4
