CSC241 Object-Oriented Programming (OOP) Lecture No. 3.

Slides:



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

UML an overview.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Downloaded From:  We may want to reuse characteristics of more than one parent class Downloaded From:
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.
Object-Oriented Programming (OOP) Lecture No. 6
2-1 © Prentice Hall, 2007 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
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.
Object-Oriented Databases
Object-Oriented Programming (OOP) Lecture No. 5 Downloaded From:
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
Chapter 14: Object-Oriented Data Modeling
Introduction To System Analysis and design
Object-Oriented Systems Analysis and Design Using UML
Object-Oriented Programming (OOP) Lecture No. 3. Abstraction ► Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only.
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.
Introduction To System Analysis and Design
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Object-Oriented Programming (OOP) CSC-2071 (3+1=4 Credits) Lecture No. 1 MBY.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Object-Oriented Programming (OOP) Lecture No. 5. Multiple Inheritance ► We may want to reuse characteristics of more than one parent class.
Object oriented classification Classification is the process of checking to see if an object belongs to a category or a class, is regarded as a basic attribute.
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.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
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.
CSC241 Object-Oriented Programming (OOP) Lecture No. 1.
Lecture 1: UML Class Diagram September 12, UML Class Diagrams2 What is a Class Diagram? A class diagram describes the types of objects in the system.
Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,
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.
 Week08.  Review Schedule Weeks 8-14  This week o Review last class o Introduce Class Diagrams o ICE-03 Sheridan SYST Engineering Quality Systems.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Object-Oriented Systems Analysis and Design Using UML Systems Analysis and Design,
Chapter 5 System Modeling. What is System modeling? System modeling is the process of developing abstract models of a system, with each model presenting.
Introduction to OOP CPS235: Introduction.
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
Object-Oriented Paradigm (OOP) Course Code: SE 101 Lecture No. 1.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Object-Oriented Programming (OOP) Lecture No. 4
Unified Modeling Language (UML)
Object Oriented Programming
Object-Oriented Analysis and Design
OBJECT RELATIONSHIPS, ATTRIBUTES, AND METHODS
Lec 3: Object-Oriented Data Modeling
UML Class Diagram.
Chapter 20 Object-Oriented Analysis and Design
Understand and Use Object Oriented Methods
Systems Analysis – ITEC 3155 Modeling System Requirements – Part 2
Object-Oriented Programming (OOP) Lecture No. 5
Object Oriented Analysis and Design
Object-Oriented Programming
From Class Diagram to Contract Diagram
Presentation transcript:

CSC241 Object-Oriented Programming (OOP) Lecture No. 3

Multiple Inheritance  We may want to reuse characteristics of more than one parent class

Example – Multiple Inheritance Mermaid

Example – Multiple Inheritance Mermaid WomanFish

Example – Multiple Inheritance Amphibious Vehicle

Example – Multiple Inheritance Amphibious Vehicle Land VehicleWater Vehicle Vehicle CarBoat

Problems with Multiple Inheritance  Increased complexity  Reduced understanding  Duplicate features

Problem – Duplicate Features  Which eat operation Mermaid inherits? Mermaid WomanFish eat … eat …

Solution – Override the Common Feature Mermaid WomanFish eat … eat … eat … Invoke eat operation of desired class

Problem – Duplicate Features (Diamond Problem)  Which changeGear operation Amphibious Vehicle inherits? Amphibious Vehicle Land VehicleWater Vehicle Vehicle CarBoat changeGear

Solution to Diamond Problem  Some languages disallow diamond hierarchy  Others provide mechanism to ignore characteristics from one side

Association  Objects in an object model interact with each other  Usually an object provides services to several other objects  An object keeps associations with other objects to delegate tasks

Kinds of Association  Class Association  Inheritance  Object Association  Simple Association  Composition  Aggregation

Simple Association  Is the weakest link between objects  Is a reference by which one object can interact with some other object  Is simply called as “association”

Kinds of Simple Association  w.r.t navigation  One-way Association  Two-way Association  w.r.t number of objects  Binary Association  Ternary Association  N-ary Association

One-way Association  We can navigate along a single direction only  Denoted by an arrow towards the server object

Example – Association  Ali lives in a House AliHouse lives-in 1 1

Example – Association  Ali drives his Car AliCar drives * 1

Two-way Association  We can navigate in both directions  Denoted by a line between the associated objects

Example – Two-way Association  Employee works for company  Company employs employees EmployeeCompany works-for 1 *

Example – Two-way Association  Yasir is a friend of Ali  Ali is a friend of Yasir YasirAli friend 1 1

Binary Association  Associates objects of exactly two classes  Denoted by a line, or an arrow between the associated objects

Example – Binary Association  Association “works-for” associates objects of exactly two classes EmployeeCompany works-for 1 *

Example – Binary Association  Association “drives” associates objects of exactly two classes AliCar drives * 1

Ternary Association  Associates objects of exactly three classes  Denoted by a diamond with lines connected to associated objects

Example – Ternary Association  Objects of exactly three classes are associated StudentTeacher Course 1 * *

Example – Ternary Association  Objects of exactly three classes are associated ProjectLanguage Person * 1 *

N-ary Association  An association between 3 or more classes  Practical examples are very rare

Composition  An object may be composed of other smaller objects  The relationship between the “part” objects and the “whole” object is known as Composition  Composition is represented by a line with a filled- diamond head towards the composer object

Example – Composition of Ali Ali Body Arm Head Leg

Example – Composition of Chair Chair SeatArm Back Leg

Composition is Stronger  Composition is a stronger relationship, because  Composed object becomes a part of the composer  Composed object can’t exist independently

Example – Composition is Stronger  Ali is made up of different body parts  They can’t exist independent of Ali

Example – Composition is Stronger  Chair’s body is made up of different parts  They can’t exist independently

Aggregation  An object may contain a collection (aggregate) of other objects  The relationship between the container and the contained object is called aggregation  Aggregation is represented by a line with unfilled- diamond head towards the container

Example – Aggregation Room Cupboard Bed ChairTable * 1 1 1

Example – Aggregation GardenPlant *

Aggregation is Weaker  Aggregation is weaker relationship, because  Aggregate object is not a part of the container  Aggregate object can exist independently

Example – Aggregation is Weaker  Furniture is not an intrinsic part of room  Furniture can be shifted to another room, and so can exist independent of a particular room

Example – Aggregation is Weaker  A plant is not an intrinsic part of a garden  It can be planted in some other garden, and so can exist independent of a particular garden

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 Circle radius draw computeArea Line length draw getLength Triangle angle draw computeArea

Example – Class Compatibility File size … open print … ASCII File … print … PDF File … print … PS File … 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 Shape LineCircleTriangle draw View

Example – Polymorphism File ASCII FilePDF FilePS File print Editor

Polymorphism – Advantages  Messages can be interpreted in different ways depending upon the receiver class Shape LineCircleTriangle draw View

Polymorphism – Advantages  New classes can be added without changing the existing model Square draw Shape LineCircleTriangle draw View

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  Shape  Line  Circle  Triangle  Menu Group View  Following classes have been identified:

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 Triangle CircleLine ShapeView nn nn nn nn Menu Group nn nn nn n n nn

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

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

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

Object Model – Graphic Editor Menu name isOpen View noOfObjects selected Shape color vertices Line length Circle radius Group noOfObjects Triangle angle nn n nn n nn n n n n nn nn 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 –Draw –Select –Move –Rotate Circle –Draw –Select –Move –Rotate

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

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

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

Group noOfObjects draw() Triangle angle draw() nn Circle radius draw() nn Line length draw() nn Shape color vertices draw() select() move() rotate() nn View noOfObjects selected add() remove() group() show() select() move() rotate() nn nn nn nn Menu name isOpen open() select() move() rotate() 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

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

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