Object-Oriented Programming (OOP) Lecture No. 5

Slides:



Advertisements
Similar presentations
Selection of Exercises Use Keyboard Arrows to Navigate.
Advertisements

Head This is a head BODY PARTS. hair This is hair BODY PARTS.
Downloaded From:  We may want to reuse characteristics of more than one parent class Downloaded From:
ASIMO. Want a robot to cook your dinner, Do your homework, Clean your house, Or get your groceries? Robots already do a lot of the jobs that we humans.
Object-Oriented Programming (OOP) Lecture No. 5 Downloaded From:
Lawrence ChungCS6359.0T1: Module 41 Module 4: Relationships.
head This is a head BODY PARTS hair This is hair BODY PARTS.
Body Parts Activity 1 Left click to go to the next slide. -OR- Click the arrow key >
Object-Oriented Programming (OOP) CSC-2071 (3+1=4 Credits) Lecture No. 1 MBY.
Object-Oriented Programming (OOP) Lecture No. 5. Multiple Inheritance ► We may want to reuse characteristics of more than one parent class.
Below the Belt Above The Belt Head Shots Extremities.
Parts of the body.
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. 1.
BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class.
CSC241 Object-Oriented Programming (OOP) Lecture No. 3.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object-Oriented Programming (OOP) Lecture No. 2. Information Hiding ► Information is stored within the object ► It is hidden from the outside world ►
Object-Oriented Programming (OOP) Lecture No. 3 Downloaded From:
Database Design – Lecture 12 Object Oriented Database Design cont’d.
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.
Association / Aggregation / Composition and inheritance
1 CSC241: Object Oriented Programming Lecture No 17.
? body parts Answer the Quiz mouth eyes feet nose toes ears fingers
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.
Do Now Questions 1.How far in advance should you signal before turning your vehicle? 2.The meaning of a hand signal when a drivers hand and arm are downward.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
UML Class & Object Diagram I
Studio Portraits.
Object-Oriented Programming (OOP) Lecture No. 4
OOP - Object Oriented Programming
Object-Orientated Analysis, Design and Programming
Object Oriented Programming
DATA REQIREMENT ANALYSIS
OBJECT ORIENTED CONCEPT
Object-Orientated Design: Part 2
Object-Oriented Analysis and Design
Object-Oriented Modeling with UML
Class diagram Description
Abstract descriptions of systems whose requirements are being analysed
OBJECT RELATIONSHIPS, ATTRIBUTES, AND METHODS
Object-Oriented Programming (OOP) Lecture No. 2
Body Position & Movement
UML Diagramming with Astah*
Object Oriented Analysis and Design
Engineering Quality Software
Software Engineering Lecture #11.
Systems Analysis and Design With UML 2
UML Class Diagram.
Software Engineering Lecture 10.
Fry Word Test First 300 words in 25 word groups
WELCOME TO GUDIANCE.
Systems Analysis – ITEC 3155 Modeling System Requirements – Part 2
BODY PARTS VOCABULARY. head mouth teeth neck eye.
Eye great ear head hair mouth It’s an ear. neck.
UNIT 6 A1 My Friends Part I.
Puzzle #1 You are driving a bus. At the first stop, two women get on. At the second stop, three men get on and one woman gets off. At the third stop,
Body word cards months This resource can be used to support adult led activities or carpet sessions and can also be used to support the learning.
BCA-II Object Oriented Programming using C++
Object Oriented Analysis and Design
Object Oriented System Design Class Diagrams
Object Oriented Design & Analysis
Information System Design
BODY PARTS head This is a head..
Introduction to Object-Oriented Software Development
Chapter 6b: Database Design Using the E-R Model
BODY PARTS head This is a head.
From Class Diagram to Contract Diagram
Presentation transcript:

Object-Oriented Programming (OOP) Lecture No. 5

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

Example – Multiple Inheritance Mermaid

Example – Multiple Inheritance Woman Fish Mermaid

Example – Multiple Inheritance Amphibious Vehicle

Example – Multiple Inheritance Vehicle Land Vehicle Water Vehicle Car Amphibious Vehicle Boat

Problems with Multiple Inheritance Increased complexity Reduced understanding Duplicate features

Problem – Duplicate Features Woman Fish eat … eat … Mermaid Which eat operation Mermaid inherits?

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

Problem – Duplicate Features (Diamond Problem) Vehicle changeGear Land Vehicle Water Vehicle Car Amphibious Vehicle Boat Which changeGear operation Amphibious Vehicle inherits?

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 Object Association Inheritance 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 House 1 1 Ali lives in a House

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

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 * 1 Employee works for company Company employs employees

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

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

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

Example – Binary Association Ali drives Car 1 * Association “drives” associates objects of exactly two classes

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

Example – Ternary Association Student Teacher * 1 * Course Objects of exactly three classes are associated

Example – Ternary Association Project Language * * 1 Person Objects of exactly three classes are associated

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 Head 1 Arm Leg Ali 2 2 Head State: Eyes, Nose, Mouth, Ears, Hair behaviour: Look, Sniff, Eat, Listen Body State: Waist, Chest Width, Shape behaviour: Digest Food, Circulates Blood, Respiration Arms State: Hands, Fingers, Nails behaviour: Move, Hold, Stretch Legs State: Feet, Fingers, Nails behaviour: Walk, Turn, Stop 1 Body

Example – Composition of Chair Back 1 Chair Gear Box State: 1, 2, 3, 4, Back behaviour: Change Gear Doors State: Open, Closed, Locked, Unlocked behaviour: Open, Close, Lock, Unlock Lights State: On, Off, Low, Medium, High behaviour: Turn On, Turn Off, Set Intensity Steering Wheel State: Angle behaviour: Turn Right, Turn Left 2 1 4 Arm Seat 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 Bed 1 Chair Room Table * 1 1 Cupboard

Example – Aggregation Garden Plant *

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