devonmanelski.com
 
Home | I.T. Management | Business Analysis & Project Management | VB.Net | SQL Server | About |

Classes and Objects
  1. Summary
  2. A Class is an encapsulation of Data and Methods. The Data is stored in Properties of the Class. The Methods operate on the Data stored in the Properties of the Class in combination with the Data that is passed as Arguments to the Methods of the Class. An Object is a specific instance of a Class which can be used to Set and Get the Value of the Object's Properties as well as call the methods of the Object.

    For example,

    'Instantiate An Object that is Defined by the cCarClass
    '------------------------------------------------------
    Dim oCarObject as cCarClass
    oCarObject = New cCarClass

    'Set the Color, Number of Doors and Engine Size
    '------------------------------------------------------------------------------------------
    oCarObject.pCarColor = "Brown"
    oCarObject.pCarDoors = 4
    oCarObject.pEngineSize = "2.5L"

    'Change the Number of Doors of the car.
    '------------------------------------------------------------------------------------------
    oCarObject.mChangeNumberOfDoors(2)

    'Always Set Object Variables to Nothing When They Are No Longer In Use
    '------------------------------------------------------------------------------------------
    oCarObject = Nothing

    An Object Model is a Conceptual Model that is similar to a Database Entity-Relationship Model. In this Conceptual Model, a Domain is defined, and within the scope of that Domain, specific entities are identified and made into Classes; so that the Software Application has a complete set of interacting objects that can fully meet the functional requirements of the software application.

    For example, for the Domain of Car Manufacturing, a Software Developer may define the following parts of the Object Model.

    1. Car Engine
      1. Data Properties
        1. Engine Size
        2. Engine Number of Cylinders
        3. Engine Valvetrain Configuration
        4. Engine Piston Stroke
        5. Engine Ignition Timing
      2. Methods
        1. Public Function mGetEngineSize(ByRef iNumberofCylinders as Integer, ByRef iValveTrainConfiguration as Integer, ByRef iPistonStroke as Integer) as Integer
        2. Public Function mSetIgnitionTiming(ByRef iEngineSize as Integer) as Integer
    2. Car Transmission
      1. Data Properties
        1. Powertrain Type
        2. Gearbox
        3. Gear Ratio
        4. Housing Type
      2. Methods
        1. Public Function mGetTransmissionConfiguration(ByRef iEngineSize as Integer, ByRef iPowerTrainType as Integer) as Integer
    3. Car Exterior
      1. Data Properties
        1. Color
        2. Sunroof
      2. Methods
        1. Public Function mSetColor(ByRef iColor as Integer) as Integer
        2. Public Function mSetSunRoofOption(ByRef bSunRoof as Boolean) as Integer

  3. An Introduction to Classes
    1. Class Properties
    2. Properties are Data Elements of a Class which are used to describe the specific implementation (or instance) of the Class when it is used within the software application. The Data Properties of a Class can be set to a Value and accessed as specified within the Class.

      For example,

      Public Class cCarClass
      Private lCarColor As String

      Public Property pCarColor() As String
      Get
      pCarColor = lCarColor
      End Get

      Set(ByVal sCarColor As String)
      lCarColor = sCarColor
      End Set
      End Property

      End Class

    3. Class Methods
    4. Methods are Procedures of a Class that perform an operation. The Methods of a Class are Function Procedures and Sub Procedures. The Names of the Procedures and the Arguments that are passed into, and returned by the Procedure, makeup the Interface of the Class.

    5. Class Events
    6. A Class Event is a Sub Procedure that is automatically called when a specific Event is triggered in the Event Driven Model of the .Net Framework, i.e. when a specific Button Control is clicked.

    7. The New and Finalize Class Events
    8. The New Event is a Sub Procedure that is part of every Class which is automatically called when the Object Variable is set to a new instance of the Class. The Finalize Event is a Sub Procedure that is also part of every Class which is also automatically called when the Object Variable is set to Nothing.

    9. Class Interface
    10. A Class Interface is made up of the Names of the Class Properties, the Names of the Class Methods and the Arguments that are passed into and returned from the Class Methods. The Data Type of the Arguments are part of the Class Interface. Class Interfaces define the ways in which Objects and Components communicate with each other and establish the foundation for interoperability. Interfaces are also used to define Class Hierarchies when using Inheritance in the Object Model.



Copyright © Devon Manelski