DOC PREVIEW
LETU COSC 2103 - Object Oriented Programming: Inheritance

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Object Oriented Programming: InheritanceWhat You Will LearnIntroductionSlide 4Base Classes & Derived ClassesSuperclass and SubclassSlide 7Design Tipprotected MembersComments on Private vs. ProtectedRelationship between Superclasses and SubclassesCreating and Using a CommissionEmployee ClassSlide 13Creating a BasePlusCommissionEmployee Class without Using InheritanceCreating a CommissionEmployee-BasePlusCommiionEmployee Inheritance HierarchyUsing protected Instance VariablesUsing protected Instance Variables AdvantagesUsing protected Instance Variables DisadvantagesReexamine HierarchyInstantiating Subclass ObjectSlide 21Software Engineering with InheritanceObject Oriented Object Oriented Programming: InheritanceProgramming: InheritanceChapter 9Chapter 922What You Will LearnWhat You Will LearnSoftware reusabilitySoftware reusability(Recycling)(Recycling)Inheriting data members and methods from Inheriting data members and methods from previously defined classespreviously defined classes33IntroductionIntroductionSoftware ReusabilitySoftware Reusabilitysaves time in program developmentsaves time in program developmentencourages use of proven, debugged codeencourages use of proven, debugged codereduces problemsreduces problemsWrite programs in general fashionWrite programs in general fashionEnables software designers to deal with Enables software designers to deal with complexity of modern softwarecomplexity of modern software44IntroductionIntroductionWhen creating a new class …When creating a new class …designate that class to inherit data members, designate that class to inherit data members, functions of previously defined functions of previously defined superclasssuperclassresult is a result is a subclasssubclassSubclass adds new data members and Subclass adds new data members and functionsfunctionsReplace and refine existing membersReplace and refine existing members55Base Classes & Derived Base Classes & Derived ClassesClassesSuperclass is more generalSuperclass is more generalstudent, shape, loanstudent, shape, loanSubclass is more specificSubclass is more specificgrad student, undergradgrad student, undergradcircle, triangle, rectanglecircle, triangle, rectanglecarloan, home improvement, mortgagecarloan, home improvement, mortgageSome languages talk ofSome languages talk ofBase class (Superclass)Base class (Superclass)Derived class (Subclass)Derived class (Subclass)66Superclass and SubclassSuperclass and SubclassInheritance produces tree like structuresInheritance produces tree like structures77Superclass and SubclassSuperclass and SubclassInheritance produces tree like structuresInheritance produces tree like structures88Design TipDesign TipImportant link between subclass and Important link between subclass and superclasssuperclassThe “IS-A” relationshipThe “IS-A” relationshipExamplesExamplesA checking account IS-A banking accountA checking account IS-A banking accountA savings account IS NOT a checking accountA savings account IS NOT a checking accountIf there is no IS-A relationship, do not If there is no IS-A relationship, do not use inheritanceuse inheritanceSun comments on the concept of inheritanceSun comments on the concept of inheritance99protectedprotected Members Membersprotectedprotected access accessIntermediate level of protection between Intermediate level of protection between publicpublic and and privateprivateprotectedprotected members accessible by members accessible bysuperclass memberssuperclass memberssubclass memberssubclass membersClass members in the same packageClass members in the same packageSubclass access to superclass memberSubclass access to superclass memberKeyword Keyword supersuper and a dot (.) and a dot (.)1010Comments on Private vs. ProtectedComments on Private vs. ProtectedUse Use protectedprotected when when Superclass should provide a service only to its Superclass should provide a service only to its subclassessubclassesShould not provide service to other clientsShould not provide service to other clientsUse Use privateprivate so that so thatSuperclass implementation can change without affecting Superclass implementation can change without affecting subclass implementationssubclass implementationsAuthor advocates avoiding Author advocates avoiding protectedprotectedInstead provide set and get methods to access Instead provide set and get methods to access privateprivate data items (see data items (see Figures 9.12Figures 9.12, , 9.139.13 in text) in text)1111Relationship between Superclasses Relationship between Superclasses and Subclassesand SubclassesSuperclass and subclass relationshipSuperclass and subclass relationshipExample: Example: CommissionEmployee/CommissionEmployee/BasePlusCommissionEmployeeBasePlusCommissionEmployee inheritance inheritance hierarchyhierarchyCommissionEmployeeCommissionEmployeeFirst name, last name, SSN, commission rate, gross sale First name, last name, SSN, commission rate, gross sale amountamountBasePlusCommissionEmployeeBasePlusCommissionEmployeeFirst name, last name, SSN, commission rate, gross sale First name, last name, SSN, commission rate, gross sale amountamountBase salaryBase salary1212Creating and Using a Creating and Using a CommissionEmployeeCommissionEmployee Class ClassClass Class CommissionEmployeeCommissionEmployeeExtends class Extends class ObjectObjectKeyword Keyword extendsextendsEvery class in Java extends an existing classEvery class in Java extends an existing classExcept Except ObjectObjectEvery class inherits Every class inherits ObjectObject’s methods’s methodsNew class implicitly extends ObjectNew class implicitly extends ObjectIf it does not extend another classIf it does not extend another class1313Creating and Using a Creating and Using a CommissionEmployeeCommissionEmployee Class ClassClass Class CommissionEmployeeCommissionEmployeeExtends class Extends class ObjectObjectKeyword Keyword extendsextendsEvery class in Java extends an existing classEvery class in Java extends an existing classExcept Except ObjectObjectEvery class inherits Every class inherits ObjectObject’s methods’s methodsNew class implicitly extends ObjectNew class implicitly extends ObjectIf it does not extend another classIf it does not extend another classView class View class


View Full Document

LETU COSC 2103 - Object Oriented Programming: Inheritance

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Object Oriented Programming: Inheritance
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 Object Oriented Programming: Inheritance 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 Object Oriented Programming: Inheritance 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?