OOP:Object Oriented ProgrammingName: Understanding OOP Author: Derrick Mead Date: 8/18/97 Lesson: 2 EncapsulationOne of the fundamental concepts of OOP is the method with which objects store and manipulate data known as Encapsulation. Each object consists of internal variables which, when exposed to outside world, become its' attributes. That is, the data that is input and output from the object. VB defines these exposed attributes as Properties. In addition to knowing what data to deal with, each object knows how to manipulate that data. Functions and Procedures that perform tasks are called Methods. A Method can be used internally or exposed to the programmer. If a Method is declared as Private then it can only be used inside the object. The outside world does not see it. The developer communicates and controls the object via the Public Interface, a set of Public Properties and Methods which the object
exposes to the outside. How an object performs its tasks is of no concern to the developer using the object. It is essentially a "Black Box".
In the pure world of OOP, objects can be created from other objects. Any properties and methods from one class are then automatically available as properties and methods of the new class. This is called Inheritance. Visual Basic provides a modified version of Inheritance commonly termed Containment. A class can still expose its childrens' properties and methods but the developer of the class must explicitly reference the child in any calls made to those properties or methods. A comparison is the best way of explaining this concept. ![]() ![]()
PolymorphismObjects can be as complex as you desire to make them. Some objects provide the functionality of several different objects with similar behaviours. This is Polymorphism, the ability to change the behaviour of a class based upon certain criteria. Lets look at an example :
Two geographic areas have different methods to calculate Sales Tax.
Region A calculates Sales Tax at a flat 5% of the Sales Total.
Region B calculates Sales Tax on a prorated basis - 6% up to $200, 4% for all sales over $200.
We can create an object class which performs the calculation for Region A, and another class for Region B. Then create a class which references both the previous objects. When you wish to calculate taxes just tell your Wrapper Class which region to use and the proper calculations are performed. Here's the code for this example :
[Lesson 1 , Lesson 2]
|
Quick searches: Site Search | Advanced Site Search |
|
By using this site you agree to its terms and conditions VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc. |