Custom Classes CIS-166
Objects VB allows the creation of new object types by creating a class. Classes may have properties, methods, and events and describe  what’s possible . Objects are particular things such as an Add button, and describe  what is . Button is a class exitButton is an instance of the class. A class type may be used to create many objects (instances).
Cookie Analogy Class = Cookie cutter (what cookie will look like) Instantiate = Make a cookie using cookie cutter (use the  NEW  keyword) Instance = Newly made cookie (object) Properties of different Instances may have different values. One cookie may have icing, another not Each cookie can have a different flavor Methods = Eat, Bake, or Crumble Events = Cookie crumbling
Reusability Reusability is a major advantage of OOP over traditional programming New classes created can be used in multiple projects. Each object created from the class can have its own property values.
Object-Oriented Terminology  Encapsulation : Object is complete by itself  Inheritance : One class can serve as the starting point for a second class Polymorphism : One word/name may be used in different places, and operates correctly for its context
Encapsulation Combination of characteristics of an object along with its behavior in "one package" Cannot make object do anything it does not already "know" how to do. Cannot make up new properties, methods, or events for an object. Sometimes referred to as data hiding, an object can expose only those data elements and procedures that it wishes.
Inheritance Ability to create a new class from an existing class Original class is called Base Class, Superclass, or Parent Class. Inherited class is called Subclass, Derived Class, or Child Class. Example: each form created is inherited from the Form class and customized to current needs Purpose of inheritance is  reusability . 
Inheritance Example Can create a class that describes a person Firstname, Lastname, Birthday properties Can create a derived class that starts from person class and adds properties, methods of a student Major, Student ID Common phrasing: “IS A” “ A student  IS A  person” denotes student as derived class from person
Polymorphism Methods having identical names, but different implementations Radio button, check boxes, and list boxes all have a Select method—the Select method operates appropriately for its class. Messagebox has multiple ways to Show, depending on arguments
Polymorphism in Practice Overloading  — Several procedures have the same name with different argument lists Argument list creates a  signature Overriding  — Refers to a method that has the same name as its base class Method in subclass takes precedence, replaces the method from the parent class.
Instance Variables Instance variables or properties store data specific to one object Separate memory locations for the variables and procedures for each instance (copy) of the object
Shared Variables, Properties Single memory location that is available for ALL objects of a class Can be accessed without instantiating an object of the class Use the Shared keyword to create 
Constructors & Destructors Constructor : Method that automatically executes when an object is instantiated Create by writing a Public Sub New procedure Destructor : Method  that automatically executes when an object is destroyed Create by writing a Finalize procedure

Coding Objects

  • 1.
  • 2.
    Objects VB allowsthe creation of new object types by creating a class. Classes may have properties, methods, and events and describe what’s possible . Objects are particular things such as an Add button, and describe what is . Button is a class exitButton is an instance of the class. A class type may be used to create many objects (instances).
  • 3.
    Cookie Analogy Class= Cookie cutter (what cookie will look like) Instantiate = Make a cookie using cookie cutter (use the NEW keyword) Instance = Newly made cookie (object) Properties of different Instances may have different values. One cookie may have icing, another not Each cookie can have a different flavor Methods = Eat, Bake, or Crumble Events = Cookie crumbling
  • 4.
    Reusability Reusability isa major advantage of OOP over traditional programming New classes created can be used in multiple projects. Each object created from the class can have its own property values.
  • 5.
    Object-Oriented Terminology Encapsulation : Object is complete by itself Inheritance : One class can serve as the starting point for a second class Polymorphism : One word/name may be used in different places, and operates correctly for its context
  • 6.
    Encapsulation Combination ofcharacteristics of an object along with its behavior in "one package" Cannot make object do anything it does not already "know" how to do. Cannot make up new properties, methods, or events for an object. Sometimes referred to as data hiding, an object can expose only those data elements and procedures that it wishes.
  • 7.
    Inheritance Ability tocreate a new class from an existing class Original class is called Base Class, Superclass, or Parent Class. Inherited class is called Subclass, Derived Class, or Child Class. Example: each form created is inherited from the Form class and customized to current needs Purpose of inheritance is reusability . 
  • 8.
    Inheritance Example Cancreate a class that describes a person Firstname, Lastname, Birthday properties Can create a derived class that starts from person class and adds properties, methods of a student Major, Student ID Common phrasing: “IS A” “ A student IS A person” denotes student as derived class from person
  • 9.
    Polymorphism Methods havingidentical names, but different implementations Radio button, check boxes, and list boxes all have a Select method—the Select method operates appropriately for its class. Messagebox has multiple ways to Show, depending on arguments
  • 10.
    Polymorphism in PracticeOverloading — Several procedures have the same name with different argument lists Argument list creates a signature Overriding — Refers to a method that has the same name as its base class Method in subclass takes precedence, replaces the method from the parent class.
  • 11.
    Instance Variables Instancevariables or properties store data specific to one object Separate memory locations for the variables and procedures for each instance (copy) of the object
  • 12.
    Shared Variables, PropertiesSingle memory location that is available for ALL objects of a class Can be accessed without instantiating an object of the class Use the Shared keyword to create 
  • 13.
    Constructors & DestructorsConstructor : Method that automatically executes when an object is instantiated Create by writing a Public Sub New procedure Destructor : Method that automatically executes when an object is destroyed Create by writing a Finalize procedure

Editor's Notes

  • #3 02/19/10 CIS-166 Classes and Objects