Download - Coding Objects
![Page 1: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/1.jpg)
Custom ClassesCustom ClassesCIS-166
![Page 2: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/2.jpg)
ObjectsObjectsVB 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 classexitButton is an instance of the class.A class type may be used to create
many objects (instances).
![Page 3: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/3.jpg)
Cookie AnalogyCookie AnalogyClass = 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 CrumbleEvents = Cookie crumbling
![Page 4: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/4.jpg)
ReusabilityReusabilityReusability is a major advantage of
OOP over traditional programmingNew classes created can be used in
multiple projects.Each object created from the class can
have its own property values.
![Page 5: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/5.jpg)
Object-Oriented Object-Oriented Terminology Terminology Encapsulation: Object is complete by
itself Inheritance: One class can serve as
the starting point for a second classPolymorphism: One word/name may
be used in different places, and operates correctly for its context
![Page 6: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/6.jpg)
EncapsulationEncapsulationCombination 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.
![Page 7: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/7.jpg)
InheritanceInheritanceAbility to create a new class from an
existing classOriginal 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.
![Page 8: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/8.jpg)
Inheritance ExampleInheritance ExampleCan 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
![Page 9: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/9.jpg)
PolymorphismPolymorphismMethods having identical names, but
different implementationsRadio 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
![Page 10: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/10.jpg)
Polymorphism in Polymorphism in PracticePracticeOverloading — 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.
![Page 11: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/11.jpg)
Instance VariablesInstance VariablesInstance variables or properties store
data specific to one objectSeparate memory locations for the
variables and procedures for each instance (copy) of the object
![Page 12: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/12.jpg)
Shared Variables, Shared Variables, PropertiesPropertiesSingle memory location that is
available for ALL objects of a classCan be accessed without instantiating
an object of the classUse the Shared keyword to create
![Page 13: Coding Objects](https://reader033.vdocuments.site/reader033/viewer/2022061220/54bba9734a7959f3288b45be/html5/thumbnails/13.jpg)
Constructors & Constructors & DestructorsDestructorsConstructor: Method that
automatically executes when an object is instantiated◦ Create by writing a Public Sub New
procedureDestructor: Method that
automatically executes when an object is destroyed◦ Create by writing a Finalize procedure