Object-Oriented Programming (OOP) Lecture No. 6

Slides:



Advertisements
Similar presentations
Introduction to Object Orientation System Analysis and Design
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
When is Orientated Programming NOT? Mike Fitzpatrick.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Inheritance & Classification Hierarchies Lecture-8.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Lecture 9 Object-Oriented Analysis
1 SWE Introduction to Software Engineering Lecture 13 – System Modeling.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
Chapter 14 (Web): Object-Oriented Data Modeling
HST 952 Computing for Biomedical Scientists Lecture 2.
Advanced Object-Oriented Programming Features
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
Object-Oriented Databases
Subdue Graph Visualizer by Gayathri Sampath, M.S. (CSE) University of Texas at Arlington.
Chapter 14: Object-Oriented Data Modeling
Lecture 6: Polymorphism - The fourth pillar of OOP - 1.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Chapter 14: Object-Oriented Data Modeling
Introduction To System Analysis and design
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
程建群 博士(Dr. Jason Cheng) 年03月
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Object-Oriented Programming (OOP) Lecture No. 3. Abstraction ► Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
Copyright 2002 Prentice-Hall, Inc. Chapter 2 Object-Oriented Analysis and Design Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
CS3773 Software Engineering Lecture 04 UML Class Diagram.
CHAPTER 13 (ONLINE): OBJECT-ORIENTED DATA MODELING © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition.
Object-Oriented Programming (OOP) Lecture No. 4. Recap – Inheritance ► Derived class inherits all the characteristics of the base class ► Besides inherited.
1 © Prentice Hall, 2002 Chapter 14: Object-Oriented Data Modeling Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R.
Databases : Data Modeling 2007, Fall Pusan National University Ki-Joune Li.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
CIS224 Software Projects: Software Engineering and Research Methods Lecture 1b Object concepts (Based on Stevens and Pooley (2006), Chapter 2) David Meredith.
CSC241 Object-Oriented Programming (OOP) Lecture No. 3.
CSC241 Object-Oriented Programming (OOP) Lecture No. 16.
Object-Oriented Data Modeling
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
CSCI-383 Object-Oriented Programming & Design Lecture 10.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Object Oriented Programming
S.Ducasse Stéphane Ducasse 1 Essential OO Concepts Stéphane Ducasse.
1 Introduction to Classes. 2 Terms and Concepts A class is... –The most important building block of any object- oriented system. –A description of a set.
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.
Introduction to OOP CPS235: Introduction.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Object-Oriented Programming: Inheritance and Polymorphism.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
C++ How to Program, 7/e. © by Pearson Education, Inc. All Rights Reserved.2.
CSCI-383 Object-Oriented Programming & Design Lecture 17.
Object-Oriented Programming (OOP) Lecture No. 4
Identifying Object Relationships, Attributes and Methods
Lec 3: Object-Oriented Data Modeling
UML Class Diagram.
Chapter 20 Object-Oriented Analysis and Design
Object Oriented Analysis and Design
Object-Oriented Programming
From Class Diagram to Contract Diagram
Presentation transcript:

Object-Oriented Programming (OOP) Lecture No. 6

Class Compatibility A class is behaviorally compatible with another if it supports all the operations of the other class Such a class is called subtype A class can be replaced by its subtype

…Class Compatibility Derived class is usually a subtype of the base class It can handle all the legal messages (operations) of the base class Therefore, base class can always be replaced by the derived class

Example – Class Compatibility Shape color vertices move setColor draw Triangle Circle Line angle radius length draw computeArea draw computeArea draw getLength

Example – Class Compatibility File size … open print … PS File ASCII File PDF File … … … print … print … print …

Polymorphism In general, polymorphism refers to existence of different forms of a single entity For example, both Diamond and Coal are different forms of Carbon

Polymorphism in OO Model In OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus) Consequently, sender of a message does not need to know exact class of the receiver

Example – Polymorphism draw Shape View draw Line Circle Triangle draw draw draw

Example – Polymorphism print File Editor print ASCII File PDF File PS File print print print

Polymorphism – Advantages Messages can be interpreted in different ways depending upon the receiver class draw Shape View draw Line Circle Triangle draw draw draw

Polymorphism – Advantages New classes can be added without changing the existing model draw Shape View draw Square Line Circle Triangle draw draw draw draw

Polymorphism – Advantages In general, polymorphism is a powerful tool to develop flexible and reusable systems

Object-Oriented Modeling An Example

Problem Statement Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

Identify Classes Extract nouns in the problem statement Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

…Identify Classes Eliminate irrelevant classes Editor – Very broad scope User – Out of system boundary

…Identify Classes Add classes by analyzing requirements Group – required to behave as a shape “Individual shapes can be grouped together and can behave as a single shape” View – editor must have a display area

…Identify Classes Following classes have been identified: Shape Group Line Circle Triangle Menu Group View

Object Model – Graphic Editor

Identify Associations Extract verbs connecting objects “Individual shapes can be grouped together” Group consists of lines, circles, triangles Group can also consists of other groups (Composition)

… Identify Associations Verify access paths View contains shapes View contains lines View contains circles View contains triangles View contains groups (Aggregation)

… Identify Associations Verify access paths Menu sends message to View (Simple One-Way Association)

Object Model – Graphic Editor Menu View Shape n n n n n n n n n n n n Line Circle Triangle Group n n n n n n

Identify Attributes Extract properties of the object From the problem statement Properties are not mentioned

…Identify Attributes Extract properties of the object Line Circle From the domain knowledge Line Color Vertices Length Circle Radius Triangle Color Vertices Angle Shape Color Vertices

…Identify Attributes Extract properties of the object Group View Menu From the domain knowledge Group noOfObjects View selected Menu Name isOpen

Object Model – Graphic Editor Menu View Shape name noOfObjects color isOpen selected n n vertices n n n n n n n n n Circle Line Triangle Group radius length angle noOfObjects n n n n n n

Identify Operations Extract verbs connected with an object Develop a graphic editor that can draw different geometric shapes such as line, circle and triangle. User can select, move or rotate a shape. To do so, editor provides user with a menu listing different commands. Individual shapes can be grouped together and can behave as a single shape.

… Identify Operations Eliminate irrelevant operations Develop – out of system boundary Behave – have broad semantics

…Identify Operations Following are selected operations: Line Circle Draw Select Move Rotate Circle Draw Select Move Rotate

…Identify Operations Following are selected operations: Triangle Shape Draw Select Move Rotate Shape Draw Select Move Rotate

…Identify Operations Following are selected operations: Group Menu Draw Select Move Rotate Menu Open Select Move Rotate

…Identify Operations Extract operations using domain knowledge View Select Move Rotate View Add Remove Group Show

n View noOfObjects Menu Shape selected name color isOpen vertices add() remove() open() n n draw() group() select() select() show() move() move() select() rotate() rotate() move() n n rotate() n n n Line n n Triangle Group n n length angle noOfObjects Circle n n radius draw() draw() draw() n n draw() n n

Identify Inheritance Search “is a kind of” by looking at keywords like “such as”, “for example”, etc “…shapes such as line, circle and triangle…” Line, Circle and Triangle inherits from Shape

…Identify Inheritance By analyzing requirements “Individual shapes can be grouped together and can behave as a single shape” Group inherits from Shape

Refining the Object Model Application of inheritance demands an iteration over the whole object model In the inheritance hierarchy, All attributes are shared All associations are shared Some operations are shared Others are overridden

…Refining the Object Model Share associations View contains all kind of shapes Group consists of all kind of shapes

…Refining the Object Model Share attributes Shape – Line, Circle, Triangle and Group Color, vertices

…Refining the Object Model Share operations Shape – Line, Circle, Triangle and Group Select Move Rotate

…Refining the Object Model Share the interface and override implementation Shape – Line, Circle, Triangle and Group Draw

View noOfObjects Menu Shape selected name color isOpen vertices add() remove() open() n n draw() n n group() select() select() show() move() move() select() rotate() rotate() move() rotate() Line Circle Triangle Group length radius angle noOfObjects draw() draw() draw() draw()

n View noOfObjects Menu Shape selected name color isOpen vertices add() remove() open() n n draw() group() select() select() show() move() move() select() rotate() rotate() move() n n rotate() n n n Line n n Triangle Group n n length angle noOfObjects Circle n n radius draw() draw() draw() n n draw() n n