St. Ambrose CSCI 275 - Understanding Inheritance and Interfaces

Unformatted text preview:

Chapter 8Thing To KnowOther Good StuffScopeCreating SubclassesUsing the Inherits Keyword to Create the Sailboat SubclassUsing the Inherits Keyword to Create a SubclassUnderstanding Abstract and Final ClassesUsing the NotInheritable KeywordOverriding a Superclass MethodOverriding MethodsOverriding and Invoking a Superclass MethodOverriding, Polymorphism, and Dynamic BindingIntroducing the Lease Subclasses and Abstract MethodsAdding an Abstract MethodsUnderstanding and Using InterfacesUnderstanding and Using InterfacesCreating a VB .NET InterfaceCreating a VB .NET InterfaceUsing Custom ExceptionsUnderstanding the Object Class and InheritanceUnderstanding the Object Class and InheritanceChapter 9Things to KnowAssociation RelationshipsIdentifying Association Relationships on Class DiagramIdentifying Association RelationshipsAssociating VB .NET Classes in a One-to-One RelationshipAdding Functionality to the Boat ClassSlide 30A One-to-Many Association RelationshipAssociating Docks and Slips: A One-to-Many Association RelationshipSlide 3311Chapter 8Chapter 8Understanding Understanding Inheritance and Inheritance and InterfacesInterfaces22Thing To KnowThing To KnowGeneralization/Specialization Generalization/Specialization class hierarchyclass hierarchySuper class and sub classSuper class and sub classAbstract classesAbstract classesMustInheritMustInheritFinal classes Final classes NotInheritableNotInheritableConcrete classesConcrete classesPolymorphismPolymorphismDynamic BindingDynamic BindingOverriding a superclass methodOverriding a superclass methodOveridableOveridableOverRidesOverRidesPrivate versus Protected accessPrivate versus Protected accessInterfacesInterfacesCreating custom exceptionsCreating custom exceptionsThe Object class and inheritanceThe Object class and inheritance33Other Good StuffOther Good StuffMethod SignaturesMethod SignaturesNameNameParameter ListParameter ListReturn TypeReturn TypeReference VariablesReference VariablesNothingNothingDateTimeDateTimeNowNowTodayTodayParameter ListsParameter ListsByValByValByRefByRefPrivatePrivateNo other object can directly No other object can directly read or modify the valuesread or modify the values•Must use methods of the Must use methods of the class to get or set valuesclass to get or set valuesEnsures encapsulation and Ensures encapsulation and information hidinginformation hidingSubClass must use SubClass must use superclass’ accessorsuperclass’ accessor44ScopeScopePrivatePrivateNo other object can directly No other object can directly read or modify the valuesread or modify the values•Must use methods of the Must use methods of the class to get or set valuesclass to get or set valuesEnsures encapsulation and Ensures encapsulation and information hidinginformation hidingSubClass must use SubClass must use superclass’ accessorsuperclass’ accessorProtectedProtectedValues can be directly Values can be directly accessed by subclasses accessed by subclasses Local variableLocal variableAccessible only to Accessible only to statements within a method statements within a method where it is declaredwhere it is declaredExists only as long as the Exists only as long as the method is executingmethod is executing55Creating SubclassesCreating Subclasses Generalization/specialization hierarchyGeneralization/specialization hierarchySuperclassSuperclass•Includes attributes and methods that are common to specialized subclassesIncludes attributes and methods that are common to specialized subclassesInstances of the subclassesInstances of the subclasses•Inherit attributes and methods of the superclassInherit attributes and methods of the superclass•Include additional attributes and methodsInclude additional attributes and methods Inherits keywordInherits keywordUsed in the class header to implement a subclassUsed in the class header to implement a subclassIndicates which class the new class is extendingIndicates which class the new class is extendingExample: Example: •Class header to define the Sailboat class as a subclass of Boat:Class header to define the Sailboat class as a subclass of Boat:Public Class SailboatPublic Class SailboatInherits BoatInherits Boat66Using the Using the Inherits Inherits Keyword to Keyword to Create the Sailboat SubclassCreate the Sailboat Subclass77Using the Using the Inherits Inherits Keyword to Keyword to Create a SubclassCreate a SubclassSub class constructor mustSub class constructor mustMyBase.New callMyBase.New call•Used to set attributes for the superclass Used to set attributes for the superclass •Must be the first statement in the constructorMust be the first statement in the constructor•Required unless the superclass includes a default Required unless the superclass includes a default constructor without parametersconstructor without parametersCalls to SubClass accessor methods for Calls to SubClass accessor methods for setting SubClass attributessetting SubClass attributes88Understanding Abstract and Final Understanding Abstract and Final ClassesClasses Concrete classesConcrete classesClasses that can be instantiatedClasses that can be instantiatedAbstract classAbstract classNot intended to be instantiatedNot intended to be instantiatedOnly used to extend into subclassesOnly used to extend into subclassesFacilitates reuseFacilitates reuseMustInherit keywordMustInherit keywordUsed in class header to declare an abstract class Used in class header to declare an abstract class Example: Example: •Class header to make the Boat class abstract: Class header to make the Boat class abstract: Public MustInherit Class BoatPublic MustInherit Class Boat99Using the NotInheritable KeywordUsing the NotInheritable Keyword A Final classA Final classA class that cannot be extendedA class that cannot be extendedCreated for security purposes or efficiencyCreated for security purposes or efficiencyCreated using the NotInheritable keywordCreated using the NotInheritable keywordExampleExample•Class header for the Payroll class :Class header for the Payroll class :Public NotInheritable Class Payroll Public NotInheritable Class Payroll Inherits EmployeeInherits Employee1010Overriding a Superclass MethodOverriding a Superclass Method Method overridingMethod overridingMethod in subclass will be


View Full Document

St. Ambrose CSCI 275 - Understanding Inheritance and Interfaces

Download Understanding Inheritance and Interfaces
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 Understanding Inheritance and Interfaces 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 Understanding Inheritance and Interfaces 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?