Conclusion: Object-Oriented Programming Demystified

Conclusion: Object-Oriented Programming Demystified

Except for some nuances I will touch on later, you should now have an idea of what object-oriented programming is all about. Base classes are always the most general, and as child classes inherit from a parent, they become more specialized. This concept will be illustrated throughout the remaining chapters as we tackle the .NET Framework classes.

As you can see, the idea in Visual Basic .NET is to build a program that uses and manages objects. The objects are reusable and extensible in that you can derive other objects from them for any specialized needs. Once the classes you write are debugged, they truly become black boxes of functionality. You place them in your programmer's toolbox and use them when you need to.

Let's do a quick recap of everything we covered in building our classes. If anything is unclear, go back and reread the sections about the topics that are still fuzzy. A solid understanding of these concepts is required to get the most out of Visual Basic .NET. In our Employee / Division class example, we covered the following:

  • Constructors. Using the New keyword, when a class is instantiated, the constructor is invoked. If the class inherits a parent class, the MyBase.New statement must be the first line of code within the constructor. This statement instantiates the parent class by calling its constructor. If that class is inherited from another class, the first line in the parent's constructor invokes its parent class and so on up the inheritance chain. You can overload constructors, but you don't need to use the Overloads keyword. The compiler is smart enough to figure out which constructor to use as long as the signatures are different.

  • Encapsulation. Hiding class data members by using the Private keyword. Encapsulation ensures that these members can be accessed only within the class itself or by way of properties from the outside world.

  • Inheritance. Inheriting all the functionality of another class and adding to it specialized methods, properties, and data members.

  • Overloading. Permits multiple variations of a method using the same name but embodying a different signature.

  • Overriding. Permits overriding the implementation of a parent class method with that of a child method with the same name.

  • Private data members. Variables that contain information specific to a particular instance of an object. In our Employee class, each instance contained the name of a specific person.

  • Properties. (including ReadOnly and WriteOnly). Permits the outside world to read or write values to private data members in a class. Within properties, a programmer can add edit checks, business rules, and error checking.

  • Virtual methods. The child implementation of a method is always called before the parent implementation.

I know this is quite a bit to digest for those of you new to object-oriented programming. Once you grok objects, however, easing into the .NET Framework will be a breeze.

note

The term grok is from Robert A. Heinlein's science-fiction novel Stranger in a Strange Land. The main character, Valentine Michael Smith, was the only survivor of the first manned mission to Mars. Martians raised him, so when he returns to Earth, he is a true innocent. Valentine uses the term grok to mean understand, as in "I grok Visual Basic .NET classes" or "Do you grok objects?" Programmers are notorious sci-fi fans, so you might already know the term. A wag once remarked that if you use the term grok in a job interview, you can write your own ticket.



Coding Techniques for Microsoft Visual Basic. NET
Coding Techniques for Microsoft Visual Basic .NET
ISBN: 0735612544
EAN: 2147483647
Year: 2002
Pages: 123
Authors: John Connell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net