The .NET framework and all of its languages are quite large, and can take quite a while to learn in their entirety. If you've never programmed in an object-orientated language before, then you should know a couple of things before jumping into .NET programming. In this article, James will provide you with primers for the object-orientated paradigm, as well as the concept of a namespace.
Prerequisites For .NET Programming - Object-orientated programming (Page 2 of 4 )
Back in the seventies when programming languages such as Assembly, C and Pascal reigned supreme, the procedural programming paradigm was the most popular way to create a complete application. Procedural programs were executed from start to finish in sequence. Functions and methods could be created and called, however both events and objects were unavailable, making it impossible benefit from object-orientated features such as code reuse, object creation and event handling.
During the eighties, object-orientated programming methods began to replace procedural ones. As the name suggests, object-orientated programming is based around the creation of objects. An object is an instantiation of a pre-created class, which can expose methods and member variables that can be manipulated and passed around in an orderly fashion.
To compare procedural programming with object-orientated programming, take a look at the following C and C++ code:
Procedural C Code:
char name = "John Doe";
printf("Your name is %s", name);
Object-Orientated C++ Code:
mc.x = 10;
cout << mc.x;
In the first example (procedural programming), our C application runs from top to bottom, without instantiating any objects or responding to any events. In the second example, we have created a new object named mc, which is an instantiation of the myClass class. The "x" attribute of the new object has its value set to 10, and is output to the screen using the operator <<() method of the cout stream (which pipes data directly to the stdout stream).
As you can see, our object-orientated code contains a complete class declaration, which is easily instantiated by one command. Object-orientated programming follows a logical layout convention and is cleanly structured.
In terms of current programming languages, both C++ and Java are good examples of object-orientated programming languages. Visual Basic contains some object-orientated features, however it isnít a truly object-orientated language due to its clumsiness and clutterness.
Both VB.NET and C# are true object-orientated programming languages. Microsoft used one simple rule when upgrading VB.NET and creating C# from scratch: If one programming language has a feature that the other doesn't, then include that feature in the language that doesn't, so that both languages are up to par with each other.
This rule has had some beneficial consequences for both languages. Visual Basic developers can now enjoy the true object-orientated style of programming: creating objects, responding to events and code reuse strategies can now be used, and benefit the programmer in many ways. C# is based on the language foundation and structure of C, C++ and Java. C# allows us to create new forms and add controls to those forms using simple drag-and-drop methods. On the other side of the scale, C# is extremely powerful, and can take advantage of classes, respond to events, and promotes strong code reuse habits.
When developing .NET applications, you will notice just how heavily the object-orientated paradigm is really used. The Object-orientated programming style is complemented by namespaces. Letís talk about namespaces now.