Chapter 2 Building Multitier Programs with ClassesThe OOP Development ApproachOOP Terminology-AbstractionOOP Terminology-EncapsulationOOP Terminology-InheritanceSlide 6Slide 7OOP Terminology- Abstract ClassesMultiple InheritanceOOP Terminology - PolymorphismReusable ObjectsMultitier ApplicationsSlide 13Slide 14Slide 15Designing Your Own ClassCreating Properties in a ClassProperty Procedure – General FormProperty Procedure – ExampleA Read-Only PropertyA Write-Only PropertyConstructors and DestructorsOverloading the ConstructorA Parameterized ConstructorAssigning Arguments to PropertiesA Basic Business ClassSlide 27Slide 28The Business TierThrowing and Catching ExceptionsWhat Exception to Throw?Inheriting from ApplicationExceptionModifying the Business ClassShared VariablesRetrieving Shared VariablesDisplaying a Second FormNamespacesSlide 38ScopeScope – Namespace levelScope – Module levelScope – Procedure LevelScope – Block LevelScope – Try/Catch BlocksScope – LifetimeAccessibility DomainsInheriting Variables and MethodsOverridingShadowingGarbage CollectionPassing Control Properties to a ComponentCreating an EnumerationThe Enum Statement – General FormThe Enum Statement – ExamplesChapter 2Building Multitier Programs with ClassesAdvanced Programming Using Visual Basic.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 2The OOP Development Approach•Large production projects are created by teams as separate building blocks•In Visual Basic.NET these building blocks are called classesA class is a blueprint for an object thatIncludes properties and methodsA class is a blueprint for an object thatIncludes properties and methodsObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 3OOP Terminology-Abstraction•A model of an object that determines–Characteristics properties–Behaviors methodsAbstractionRealityObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 4OOP Terminology-Encapsulation•Combination of characteristics of an object along with its behaviors one “package”•Data hiding–Properties and procedures are hidden–Programmer controls “exposure” of properties and methods available to other objects•Need example?? – Office clipart?Object-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 5OOP Terminology-Inheritance•The ability to create a new class from an existing class•The existing (original) class is called the base, superclass, or parent•The inherited class is called the derived, subclass, or child•A derived class has an “is a” relationship with its base classObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 6OOP Terminology-InheritancePublic Class frmMain Inherits System.Windows.Forms.FormPublic Class frmMain Inherits System.Windows.Forms.FormObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 7OOP Terminology-Inheritance•Inheritance supports reusability•Place common code in a base class•Derived classes can call shared functionsReusability – creation of object functionality that may be used inmultiple projectsReusability – creation of object functionality that may be used inmultiple projectsObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 8OOP Terminology-Abstract Classes•Created for specific use as a base class•Cannot create instances of abstract classes•Derived classes can call shared functions•Derived class methods override methods in the base classAn abstract class is a class created strictly for the purpose of inheritanceAn abstract class is a class created strictly for the purpose of inheritanceObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 9Multiple InheritanceObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 10OOP Terminology - Polymorphism•Methods with identical names have different implementations•The Select method is different for radio buttons, check boxes, and list boxes•Allows a single class to have more than one method with different argument listsPolymorphism is the ability to take onmany shapes or forms.Polymorphism is the ability to take onmany shapes or forms.Object-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 11Reusable Objects•Classes created may be used in multiple projects•Example – Microsoft Spell CheckerObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 12Multitier Applications•Three-tier applications are popular–Presentation tier–Business tier–Data tier•Goal is to write components that can be replaced without replacing other components•“Plug-in” new componentsApplications designed in components (services) where each section performspart of the necessary actions.Applications designed in components (services) where each section performspart of the necessary actions.Object-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 13Multitier ApplicationsObject-Oriented ProgrammingObject-Oriented ProgrammingUser Services Business Services Data ServicesUser Interface Forms Controls MenusBusiness Object Validation Calculations Business logic Business rulesData Retrieval Data storage© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 14Multitier Applications•Presentation tier the user interfaceYou can change the method of delivery withoutchanging the processingYou can change the method of delivery withoutchanging the processing© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2- 15Multitier Applications•Business tier class(es) that handle the data–Calculations–Validation to enforce business rules•Data tier retrieving and storing the data in a databaseObject-Oriented ProgrammingObject-Oriented Programming© 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2-
View Full Document