Unformatted text preview:

Chapter 6 – Objects and ClassesSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Slide 55Slide 56Slide 57Slide 58Slide 59Slide 60Slide 61Slide 62Slide 63Slide 64Slide 65Slide 66Slide 67Slide 68Slide 69Slide 70Slide 71Slide 72Slide 73Slide 74Slide 75Slide 76Slide 77Slide 78Slide 79Slide 80Slide 81Slide 82Slide 83Slide 84Slide 85Slide 86Slide 87Slide 88Slide 89Slide 90Slide 91Slide 92Slide 93Slide 94Slide 95Slide 96Slide 97Slide 98Slide 99Slide 100Slide 101Slide 102Slide 103Slide 104Slide 105Slide 106Slide 107Slide 108Slide 109Slide 110Slide 111Slide 112Slide 113Slide 114Slide 115Slide 116Slide 117Slide 118Slide 119Slide 120The Visual Basic .NET Coach1Chapter 6 – Objects and ClassesObjects are the basic building blocks of a program. Objects included in Visual Basic .NET make the development of complex applications easier because you do not have to concern yourself with the creation of objects and their properties.Visual Basic .NET allows you to create your own objects both by code and visually from existing objects contained within Visual Basic .NET.The Visual Basic .NET Coach26.1 Object-Oriented Development ConceptsA real object-oriented programming language supports three basic concepts: encapsulation, polymorphism, and inheritance. It is easier to understand these concepts by providing a parallel to real-world.A Real-World ExampleThink about an object that everyone is familiar with, a TV. Could you explain every detail of how a show is broadcast and displayed on TV? Probably not. How is a TV built? Somewhere someone has designed a set of blueprints that specifically outline the necessary parts and their configuration. These blueprints would specify the internal and external characteristics that define how the TV would operate.There are a great many variations in television design. If you had a set of blueprints for the latest 65-inch HDTV, you would have the information required to build a great TV, but you couldn’t watch a program on the blueprints.The TV would not come set to the exact station you would want when you receive it. It comes with an interface in the form of a remote control. This interface allows the user to set certain of the TV’s characteristics to specific values.Chapter 6 – Objects and ClassesThe Visual Basic .NET Coach3Object-Oriented ConceptsIn Visual Basic .NET you use a class to describe the properties and actions associated with an object in the same manner as a blueprint describes the properties and functionality of a TV.A developer should not allows access to the properties of a class except by specific routines that the developer creates. These routines are referred to as methods of the class.A class does not serve as a functioning version of the item you are creating. The class must be built just as your TV is assembled. When you wish to create a functioning version of the class, you must create an object. While the computer does not have an assembly line to create an object, it does have to allocate the memory required for the object and initialize any variables. This process of creating an object from a class is known as instantiating an object.Chapter 6 – Objects and ClassesThe Visual Basic .NET Coach4EncapsulationEncapsulation enables the programmer designing the class to dictate what types of operations are permissible upon a class without permitting other programmers access to the inner workings of the class. The class designer allows other programmers to have the complexity of a class hidden and ensures that other programmers can only use the class in ways intended by the programmer designing the class.You have used objects like text boxes, labels, and buttons without knowledge of their internal workings. The properties and events accessed only allowed you to manipulate the objects in ways predetermined by the developers of the objects.Chapter 6 – Objects and ClassesThe Visual Basic .NET Coach5PolymorphismThe concepts of having one name but a different behavior depending upon the object it belongs to is known as polymorphism. Many of the controls that you have built your application from have properties, methods, or events with the same name but take on a slightly different meaning from control to control.You have been using polymorphism when you perform the basic mathematical operations. Regardless of the data type you wish to perform addition or subtraction on, you use operators like + or -. You do not require a different operator to perform an addition for each data type.When you design objects that have similar functions, it is helpful to design them with polymorphism in mind.Chapter 6 – Objects and ClassesThe Visual Basic .NET Coach6InheritanceOne of the keys to efficient development of applications is the ability to reuse the code that you previously developed. One way programmers accomplish this is to cut and paste code from one project to another. A better method, inheritance, is to build new classes from previous ones without modifying the original code.If you use the former method and then later discover a bug in the original code, you must go back and modify the code in all the classes you copied the bug into. With inheritance, if you modify the original class, all the classes based on that change would be updated automatically.The other problem, although not quite as severe, is the waste of a lot of unnecessary disk space by having multiple copies of the source code each time you copy it.Chapter 6 – Objects and ClassesThe Visual Basic .NET Coach7Drill 6.1Match the following items to the closest example.A inheritance 1 When a function takes on different meanings based upon what object is being used.B polymorphism 2 The hiding of the details of the implementation from a developer.C encapsulation 3 The ability to create a new class based on the definition of an existing one.D instantiation 4 The “blueprint” of an object.E class 5 The creation of an object from a class.Chapter 6 – Objects and ClassesAnswer: A – 3, B – 1, C – 2, D – 5, E - 4The Visual Basic .NET Coach8Drill 6.2Specify all the properties and functions of your television


View Full Document

UCR CS 5 - Chapter 6 Objects and Classes

Download Chapter 6 Objects and Classes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 6 Objects and Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 6 Objects and Classes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?