Object-Oriented Programming (OOP) Lecture No. 4

Slides:



Advertisements
Similar presentations
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
Advertisements

Inheritance & Classification Hierarchies Lecture-8.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Object-Oriented Programming (OOP) Lecture No. 6
CS-2135 Object Oriented Programming
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
2.5 OOP Principles Part 2 academy.zariba.com 1. Lecture Content 1.Polymorphism 2.Cohesion 3.Coupling 2.
Introduction to Object-oriented programming and software development Lecture 1.
Object-Oriented Programming (OOP) Lecture No. 3. Abstraction ► Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Object-Oriented Programming (OOP) CSC-2071 (3+1=4 Credits) Lecture No. 1 MBY.
Object-Oriented Programming (OOP) Lecture No. 4. Recap – Inheritance ► Derived class inherits all the characteristics of the base class ► Besides inherited.
CSC241 Object-Oriented Programming (OOP) Lecture No. 3.
Introduction to Object-Oriented Programming Lesson 2.
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Introduction to Object Oriented Programming Lecture-3.
Inheritance and Polymorphism
Advanced Programming in Java
Modern Programming Tools And Techniques-I
Intro to Computer Science II
Object-Orientated Programming
Visit for more Learning Resources
Object-Oriented Programming Concepts
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Ch 10- Advanced Object-Oriented Programming Features
Object-Oriented Programming (OOP) Lecture No. 45
Inheritance and Polymorphism
Object-Oriented Programming (OOP) Lecture No. 1
Testing Object-Oriented Software Concepts and Definitions
Object-Oriented Programming
Object Oriented Concepts -II
Phil Tayco Slide version 1.0 Created Nov 6, 2017
Week 4 Object-Oriented Programming (1): Inheritance
An Introduction to Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
Objects First with Java A Practical Introduction using BlueJ
Object Oriented Analysis and Design
Lecture 23 Polymorphism Richard Gesick.
Inheritance Chapter 5.
Object-oriented Design in Processing
MSIS 670 Object-Oriented Software Engineering
Lecture 22 Inheritance Richard Gesick.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Polymorphism Phil Tayco San Jose City College Slide version 1.1
Week 6 Object-Oriented Programming (2): Polymorphism
Basic Object Oriented Approach
Inheritance and Polymorphism
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
topics object oriented design objects and classes properties
Inheritance in Graphics
Objects First with Java A Practical Introduction using BlueJ
Object-Oriented Programming: Inheritance and Polymorphism
Object-Oriented Programming (OOP) Lecture No. 5
Fundaments of Game Design
Chapter 14 Abstract Classes and Interfaces
Objects First with Java A Practical Introduction using BlueJ
Object Oriented Analysis and Design
Object-oriented Design in Processing
Object-Oriented PHP (1)
Object-Oriented Programming (OOP) Lecture No. 27
Binding 10: Binding Programming C# © 2003 DevelopMentor, Inc.
Object-oriented Design in Processing
Computer Science II for Majors
Presentation transcript:

Object-Oriented Programming (OOP) Lecture No. 4

Recap – Inheritance Derived class inherits all the characteristics of the base class Besides inherited characteristics, derived class may have its own unique characteristics Major benefit of inheritance is reuse

Concepts Related with Inheritance Generalization Subtyping (extension) Specialization (restriction)

Generalization In OO models, some classes may have common characteristics We extract these features into a new class and inherit original classes from this new class This concept is known as Generalization

Example – Generalization Line color vertices length Circle color vertices radius move setColor getLength Triangle color vertices angle move setColor computeArea move setColor computeArea

Example – Generalization Shape color vertices move setColor Triangle Circle angle radius Line computeArea length computeArea getLength

Example – Generalization Student name age gender program studyYear Teacher name age gender designation salary Doctor name age gender designation salary study heldExam eat walk teach takeExam eat walk checkUp prescribe eat walk

Example – Generalization Person name age gender eat walk Student Teacher Doctor program studyYear designation salary designation salary study heldExam teach takeExam checkUp prescribe

Sub-typing & Specialization We want to add a new class to an existing model Find an existing class that already implements some of the desired state and behaviour Inherit the new class from this class and add unique behaviour to the new class

Sub-typing (Extension) Sub-typing means that derived class is behaviourally compatible with the base class Behaviourally compatible means that base class can be replaced by the derived class

Example – Sub-typing (Extension) Person name age gender eats walks Student program studyYear study takeExam

Example – Sub-typing (Extension) Shape color vertices setColor move Circle radius computeCF computeArea

Specialization (Restriction) Specialization means that derived class is behaviourally incompatible with the base class Behaviourally incompatible means that base class can’t always be replaced by the derived class

Example – Specialization (Restriction) Person age : [0..100] … setAge( a ) … age = a Adult If age < 18 then error else age = a age : [18..100] … setAge( a ) …

Example – Specialization (Restriction) IntegerSet … add( elem ) … add element to the set If elem < 1 then error else add element to the set NaturalSet … add( elem ) …

Overriding A class may need to override the default behaviour provided by its base class Reasons for overriding Provide behaviour specific to a derived class Extend the default behaviour Restrict the default behaviour Improve performance

Example – Specific Behaviour Shape color vertices draw move setColor Triangle Circle angle radius Line draw computeArea length draw computeArea draw

Example – Extension Window DialogBox width height open close draw 1- Invoke Window’s draw 2- draw the dialog box controls enable draw

Example – Restriction IntegerSet NaturalSet … add( elem ) Add element to the set If elem < 1 then give error else Add element to the set NaturalSet … add( elem ) …

Example – Improve Performance Shape Class Circle overrides rotate operation of class Shape with a Null operation. color coord draw rotate setColor Circle radius draw rotate

Abstract Classes An abstract class implements an abstract concept Main purpose is to be inherited by other classes Can’t be instantiated Promotes reuse

Example – Abstract Classes Person name age gender eat walk Student Doctor Teacher Here, Person is an abstract class

Example – Abstract Classes Vehicle color model accelerate applyBrakes Truck Car Bus Here, Vehicle is an abstract class

Concrete Classes A concrete class implements a concrete concept Main purpose is to be instantiated Provides implementation details specific to the domain context

Example – Concrete Classes Person Student Doctor program studyYear Teacher study heldExam Here, Student, Teacher and Doctor are concrete classes

Example – Concrete Classes Vehicle Truck Car Bus capacity load unload Here, Car, Bus and Truck are concrete classes