Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

OOP: Inheritance By: Lamiaa Said.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
UML – Class Diagrams.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Inheritance using Java
Programming Languages and Paradigms Object-Oriented Programming.
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Database Management System Prepared by Dr. Ahmed El-Ragal Reviewed & Presented By Mr. Mahmoud Rafeek Alfarra College Of Science & Technology Khan younis.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
Object Oriented Software Development
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Object Oriented Programming
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Coming up: Inheritance
Topics Inheritance introduction
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-Oriented Design
Unified Modeling Language (UML)
Object-Oriented Modeling
The Movement To Objects
Inheritance ITI1121 Nour El Kadri.
Object-Oriented Analysis and Design
Final and Abstract Classes
Analysis and Design with UML: Discovering Classes and Relationships
Object Oriented Concepts -II
Week 4 Object-Oriented Programming (1): Inheritance
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Analysis and Design with UML: Discovering Classes and Relationships
Analysis and Design with UML: Discovering Classes and Relationships
Object Oriented Analysis and Design
Domain Class Diagram Chapter 4 Part 2 pp
Software Engineering Lecture #11.
MSIS 670 Object-Oriented Software Engineering
Object-Oriented Programming
UML Class Diagram.
Advanced Programming Behnam Hatami Fall 2017.
Software Design Lecture : 14.
Inheritance and Polymorphism
Object-Oriented Programming
Analysis and Design with UML: Classes and Relationships
Fundaments of Game Design
Object-Oriented Programming
Object Oriented Analysis and Design
Final and Abstract Classes
Object-Oriented Programming
Extending Classes Through Inheritance
ADVANCED OBJECT-ORIENTED PROGRAMMING
Computer Science II for Majors
From Class Diagram to Contract Diagram
Presentation transcript:

Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy

Object-Oriented Principles OOP Encapsulation (class) -- Information Hiding -- Separation of Interface and Implementation -- Standardization -- Access Control mechanisms (private /public) Inheritance -- Hierarchy -- Reusability -- Extensibility -- Expressive power -- Reflects many real-world problems Polymorphism -- Many forms of same function -- Runtime Binding -- Abstract Classes -- Interfaces -- Uniformity 11/7/2018 B.Ramamurthy

Encapsulation Realized using the “class” construct Encapsulate the data and provide access methods, update methods etc. related to the encapsulated data. Presentation: use a class diagram 11/7/2018 B.Ramamurthy

Classes and Relationships A solution to a problem may contain many related classes. Five basic types of relationships among classes are defined by UML: Association Aggregation Composition Generalization (inheritance) Refinement 11/7/2018 B.Ramamurthy

Inheritance Classes in a typical application domain often exhibit some common properties and/or operations. In this case, the classes are associated through an inheritance relationship. Classes participating in a inheritance relationship can be visualized as a hierarchy. 11/7/2018 B.Ramamurthy

Inheritance (contd.) Inheritance relationship also represents generalization/specialization. Most general class is at the top of the hierarchy and the other classes are derived from this general class and specialized by adding or modifying properties and capabilities. 11/7/2018 B.Ramamurthy

Example: A Bank Hierarchy BankClass has a has a has a Account [ ] MortgageSVC BrokerageSVC is a is a Savings Checking is a : use inheritance has a : use aggregation, or composition 11/7/2018 B.Ramamurthy 6

Inheritance Mechanisms Two mechanisms in Java for realizing inheritance: 1. Single inheritance through “extend”ing existing classes (both concrete and abstract) 2. Multiple inheritance through “interface” and “implementation”(s) 11/7/2018 B.Ramamurthy

Inheritance through “extends” class subclass extends superclass { class definition } Example: class Windstar extends FordCar // meaning it inherits from class Fordcar{ ....} Windstar myCar; In this example, FordCar is the super-class and Windstar is a sub-class and myCar is an object reference to Windstar class. myCar = new Windstar(green); // object instantiated 11/7/2018 B.Ramamurthy

Class Structure for Bank Problem classes of Bank hierarchy class Savings extends Account {...} class Checking extends Account { …} class Bank { Account acctList[] = new Account(100); // 100 accounts are instantiated MortgageSVC someName1 = new MortgageSVC(); BrokerageSVC someName2 = new BrokerageSVC(); etc.} 11/7/2018 B.Ramamurthy

Modifers Modifiers are special words that are added in front of methods, data fields, classes to specify their nature. Visibility modifiers: private, public, protected Protected modifier is used when the entity needs to be available to the subclass but not to the public. 11/7/2018 B.Ramamurthy

Example: Employee Hierarchy public: name private: wage_rate and hours uses super class Application uses Employee class, Paid_Employee class Paid_Employee uses public compute_wages(); sub class 11/7/2018 B.Ramamurthy

Need for “protected” modifier : limited access Employee is a super class, Paid_Employee is a sub class derived from it. If we make wage_rate and hours public they are available to the whole world. If you make them private then they are not accessible to the sub class unless there are set and get functions. Protected access control provides a mechanism for hiding details from the world but making it available to sub classes. 11/7/2018 B.Ramamurthy

Attributes (Data) Modifiers Data with no modifier is visible to sub-class within the same package but not to sub-class outside the package. Private data is available only within the class in which it is defined. Protected is available to the class and all its sub-classes. Public is available to all class. 11/7/2018 B.Ramamurthy

Example: class Automobile public … startEngine{ } public … accelerate{ } public Shift_gear; // in automatic cars //this will be private protected gloveCompartment; // you have access not the burglar private odometer; protected engine; // driver doesn’t access to it // but a mechanic does } 11/7/2018 Ramamurthy

Types of Genralization Which one to use? Inheritance Abstract class is a partially defined class. It cannot be instantiated. Example: Federal EPA may set the policies (what is to be done) but their implementation (how) is done at state level. Extending a concrete class Extending an abstract class Implementing an interface 11/7/2018 B.Ramamurthy

Inheritance Continuum Concrete super class Completely abstract class or interface Use extends to make sub class A sub class implements the interface At least one method abstract. Use extends to make sub class. 11/7/2018 B.Ramamurthy

Shapes Hierarchy Shapes Hierarchy Shape : abstract class ShapePointCircleCylinder Circle extends Point super class Cylinder extends Circle super class You add on to or redefine super class methods and data. 11/7/2018 B.Ramamurthy

Abstract Class (ABC) and methods An abstract class is a class in which one or more methods are declared but not defined. Declaration of the methods can be omitted since it makes no sense to implement them in the super class. Am abstract method has “abstract” modifier in front of it. ABC cannot be instantiated. Sole purpose of ABC is to provide an appropriate super class from which classes may inherit. Classes from which objects can be instantiated are called concrete classes. 11/7/2018 B.Ramamurthy

Example for Superclass Framework public abstract class EPA { \\ different data public abstract void emission_control(); other methods may be defined } class CA_EPA extends EPA { void emission_control () { //implementation } class NY_EPA extends EPA { void emission_control () { // implementation } 11/7/2018 B.Ramamurthy

Interface and Implementation An interface is where all the methods are abstract. A Java class can extend only one class but can implement many interfaces. This is how multiple inheritance is realized in Java. 11/7/2018 B.Ramamurthy

Interface An interface essentially takes the abstract class concept to the extreme. When a class contains all abstract methods and/or constants, it can be implemented using an interface. It contains just constants, abstract methods or both. Many different implementations can be realized from a single interface. The concept of interface-implementation is the core of the Java event model. 11/7/2018 B.Ramamurthy

Inheritance through Interfaces Interface provides a framework for a system of classes. Interfaces are implemented by other classes. A class may implement more than one interface. Java Event model exemplifies interface + implementation technique. Ex: MyApplet extends applet implements MouseListerner, MouseMotionListener 11/7/2018 B.Ramamurthy

Summary Inheritance implements a very useful relationship between classes. Inheritance lets you extend and reuse existing classes / library of classes. We have covered the fundamentals of OO(Design/Analysis/Programming) Your task is to relate the concepts to your projects. class, object, abstract class, inheritance, interface and implementation are the essential components of OOD/A/P. 11/7/2018 B.Ramamurthy