Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

OOP:Object Oriented Programming


Name: Understanding OOP
Author: Derrick Mead
Date: 8/18/97

Description: Volumes could be written about OOP and Visual Basic. Here we skim the vital concepts and show some code samples that may be of use as you learn.

Many thanks to Derrick for graciously providing this tutorial; check out his VBJones Web Site.

Controls needed: N/A
Level: All


What is Object Oriented Programming?

Object Oriented Programming allows developers to mimic real world items and concepts. In an OOP world, each object knows what information describes itself and what actions it can perform with that information. OOP allows developers to create reusable objects that interact with each other to form complex entities.

Definition of Classes

A "Class" is a template which defines the attributes (properties in VB) and the actions or methods which can be performed upon those attributes for a given type of entity. The class definition is used to create "Instances" of the class, which are the actual objects used within your application.

A Class is generally considered to be a "Black Box". That is, you can use the object created from a Class without knowing how the internal code works. All the developer needs to know is which methods to call to perform certain functions. How those functions perform their tasks is hidden.

Programmers generally create a Class for each separate entity used within their application. Classes allow developers to write modifiable, readable, reusable code.

Objects = Attributes + Actions

An object is an "Instance" of a Class. In Visual Basic you can create any number of "Object Variables" from a single Class Definition. Each object knows what data describes it and how to manipluate that data.

Each data item is called an "Attribute" in OOP. Visual Basic implements these attributes as "Properties". Properties are exposed through the Public Interface of an object. Each object can have internal variables, not seen by users, which are used to store information the object requires to perform its task(s).

Figure 1.2a : An Object Which Exposes Public Properties

 VERSION 1.0 CLASS
 BEGIN
 MultiUse = -1 'True
 END
 Attribute VB_Name = "clsPerson"
 Attribute VB_Creatable = False
 Attribute VB_Exposed = False

 'Internal Member Variables
 Private mFirstName as String

 'Public Properties

 Public Property Let FirstName ( Value as String)
 'assign Value to internal variable from the outside world

      mFirstName = Value

 End Property

 Public Property Get FirstName ( ) as String
 'retreive internal variable and expose to outside world

      FirstName = mFirstName

 End Property

Objects not only contain their own data but they know how to perform tasks on that data. Tasks are performed by various functions and procedures defined in the Class Definition.These functions and procedures are called Methods in OOP. Once again only those Methods exposed by the Public Interface are available to outside users.

Figure 1.2b : An Object Which Exposes Public Methods

 VERSION 1.0 CLASS
 BEGIN
 MultiUse = -1 'True
 END
 Attribute VB_Name = "clsPerson"
 Attribute VB_Creatable = False
 Attribute VB_Exposed = False

 'Internal Member Variables
 Private mFirstName as String
 Private mLastName as String

 'Public Properties

 Public Property Let FirstName ( Value as String)
 'assign Value to internal variable from the outside world

      mFirstName = Value

 End Property

 Public Property Get FirstName ( ) as String
 'retreive internal variable and expose to outside world

      FirstName = mFirstName

 End Property

 Public Property Let LastName ( Value as String)
 'assign Value to internal variable from the outside world

      mLastName = Value

 End Property

 Public Property Get LastName ( ) as String
 'retreive internal variable and expose to outside world

      LastName = mLastName

 End Property

 'Public Methods

 Public Function FullName ( ) as String
 'retreives the persons full name

      FullName = mFirstName & " " & mLastName

 End Function

[Lesson 1 , Lesson 2]




Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.