1 / 22

Clearly Visual Basic: Programming with Visual Basic 2008

Clearly Visual Basic: Programming with Visual Basic 2008. Chapter 27 I Love this Class. Objectives. Define a class Instantiate an object from a class that you define Add Property procedures to a class Include data validation in a class Create a default constructor

tristar
Download Presentation

Clearly Visual Basic: Programming with Visual Basic 2008

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 27 I Love this Class

  2. Objectives • Define a class • Instantiate an object from a class that you define • Add Property procedures to a class • Include data validation in a class • Create a default constructor • Include methods in a class Clearly Visual Basic: Programming with Visual Basic 2008

  3. That’s a Real Classy Object • Object-oriented programming language • Allows the programmer to use objects to accomplish a program’s goal • Class • Pattern or blueprint that the computer follows when creating an object • Object • Instantiated (created) from a class • Referred to as an instance of a class Clearly Visual Basic: Programming with Visual Basic 2008

  4. That’s a Real Classy Object (continued) • Attributes • Characteristics that describe an object • Behaviors • Include methods and events • Methods • Operations (actions) that the object is capable of performing • Events • Actions to which an object can respond Clearly Visual Basic: Programming with Visual Basic 2008 4

  5. That’s a Real Classy Object (continued) • A class • Encapsulates all of the attributes and behaviors of the object it instantiates • Class statement • Used to define a class • Pascal case • Capitalize the first letter in the name and the first letter in any subsequent words in the name Clearly Visual Basic: Programming with Visual Basic 2008 5

  6. Clearly Visual Basic: Programming with Visual Basic 2008 6

  7. Revisiting the Willow Pools Application • Willow Pools application • Calculates and displays both the volume of a rectangular pool and the amount of water required to fill the pool • Volume • Calculated by multiplying the pool’s length by its width and then multiplying the result by the pool’s depth Clearly Visual Basic: Programming with Visual Basic 2008 7

  8. Clearly Visual Basic: Programming with Visual Basic 2008 8

  9. Who Owns that Property? • When an application instantiates an object: • Only the Public members of the object’s class are made available to the application • Property procedure • Used to create a Public property • Figure 27-4 • Code contained in the Get block allows application to retrieve the contents of the Private variable • Code in the Set block allows an application to assign a value to the Private variable Clearly Visual Basic: Programming with Visual Basic 2008 9

  10. Clearly Visual Basic: Programming with Visual Basic 2008 10

  11. Clearly Visual Basic: Programming with Visual Basic 2008 11

  12. Who Owns that Property? (continued) • Get statement • Begins with the keyword Get and ends with the keywords End Get • Set statement • Begins with the keyword Set and ends with the keywords End Set Clearly Visual Basic: Programming with Visual Basic 2008 12

  13. Constructive Behavior is the Key to Success • Constructor • Class method whose instructions are processed by the computer when an object is instantiated • Responsible for creating the object and initializing the class’s Private variables • Default constructor • Constructor that has no parameters • A class can have only one Clearly Visual Basic: Programming with Visual Basic 2008 13

  14. Clearly Visual Basic: Programming with Visual Basic 2008 14

  15. Methods Other than Constructors • Methods included in a class • Can be either Sub procedures or Function procedures • Method name • Should be entered using Pascal case • First word should be a verb, and any subsequent words should be nouns and adjectives Clearly Visual Basic: Programming with Visual Basic 2008 15

  16. Clearly Visual Basic: Programming with Visual Basic 2008 16

  17. Using the Pattern to Create an Object • After defining a class: • It can then be used to instantiate one or more objects • Figure 27-9 • Shows two versions of the basic syntax to instantiate an object Clearly Visual Basic: Programming with Visual Basic 2008 17

  18. Clearly Visual Basic: Programming with Visual Basic 2008 18

  19. Clearly Visual Basic: Programming with Visual Basic 2008 19

  20. Pool Supplies Application • Pool Supplies • Sells a water clarifier designed to combat a common problem in swimming pools: cloudy water • Recommends one ounce of SoClear clarifier per 5000 gallons of water • Manager wants an application that calculates the: • Number of gallons of water contained in a pool • Required number of ounces of clarifier Clearly Visual Basic: Programming with Visual Basic 2008 20

  21. Summary • Objects used in an object-oriented program • Instantiated (created) from classes • Class statement • Used to define a class • When naming the Private variables in a class: • Begin the name with the underscore character • When an object is instantiated in an application: • Public members of the class are exposed to the application Clearly Visual Basic: Programming with Visual Basic 2008

  22. Summary (continued) • Property procedure • Used to create a Public property • Get block allows an application to access the contents of the Private variable • Class • Can have one or more constructors • Names of methods in a class • Should be entered using Pascal case Clearly Visual Basic: Programming with Visual Basic 2008 22

More Related