SlideShare a Scribd company logo
9
Most read
16
Most read
20
Most read
OO Relationships DOEACC B-Level OODBMS 2011 Taher S. 3. Object Oriented Data Model
Relationships They represent logical links between two or more entities or objects. Residence is an example of a relationship that can exist between the entities City and Employee; Exam is an example of a relationship that can exist between the entities Student and Course. An instance of a relationship is an n-tuple made up of instances of entities, one for each of the entities involved. The pair of objects made up of the employee named Johanssen and the city Stockholm, or the pair of objects made from the employee Peterson and the city Oslo, are examples of instances in the relationship Residence.
Example of Relationships
Types of Relationships We’re going to look at the way we define the relationships between classes so we know how objects can relate to each other. Following sorts of relationships exist: Aggregation Inheritance Using Association Instantiation
1. Aggregation a.k.a Composition Different authors use different terms for the idea of containment. UML has a very specific use (and different symbols) of the terms aggregation and composition, though this is not necessarily consistent with OO authors.  UML aggregation is “weak containment”, usually implemented with pointers, and the symbol is an open diamond. Composition is “strong containment”, implemented by value, and the symbol is a filled diamond.
1. Aggregation a.k.a Composition An aggregate object is one which contains other objects. For example, an Airplane class would contain Engine, Wing, Tail, Crew objects. Sometimes the class aggregation corresponds to physical containment in the model (like the airplane). But sometimes it is more abstract (e.g. Club and Members).   The test for aggregation is to see if there is a whole/part relationship between two classes (“hasa”). A synonym for this is “part-of”.
2. Inheritance- Terminology When we use inheritance, we have classes at the top of the hierarchy that are known variously as: Generalization Parent Superclass Base Abstract And classes at the bottom of the hierarchy (or those which inherit from some other class) known variously as: Specialization Child Subclass Derived Concrete
2. Inheritance The classes toward the top of an inheritance hierarchy tend to be abstract classes that won’t have any objects instantiated from them. The bottom most classes of the hierarchy are the concrete classes from which we actually make objects that do work for us.
Inheritance- Generalizations & Specializations Generalizations represent logical links between an entity E, known as  parent  entity, and one or more entities E1,...,En called  child  entities, of which E is more general, in the sense that they are a particular case. In this situation we say that E is a  generalization of E1,...,En  and that the entities E1,...,En are  specializations  of E.
2. Inheritance- Generalizations & Specializations
Generalization- Types A generalization is  total  if every instance of the parent entity is also an instance of one of its children, otherwise it is  partial. A generalization is  exclusive  if every instance of the parent entity is at   most an instance of one of the children, otherwise it is  overlapping. The generalization Person, of Man and Woman is total (the sets of men and the women constitute ‘all’ the people) and exclusive (a person is either a man or a woman). The generalization Vehicle of Automobile and Bicycle is partial and exclusive, because there are other types of vehicle (for example, motor bike) that are neither cars nor bicycle. The generalization Person of Student and Employee is partial and overlapping, because there are students who are also employed.
Generalization- Types
2. Inheritance- Adv & DisAdv Advantages: Avoid redundant code by sharing it between classes: Inheritance relationships let us avoid the redundancy of declaring the same instance variables and behavior in a group of related classes. For instance, Dogs and Cats don’t both need a name variable; they can inherit it from Pet. Enforcing standards at a design level (interfaces) Programming-by-drag-and-drop (components) Avoid redundant code by sharing it between projects (reuse)Shared code allows for rapid prototyping via reuse. Shared code produces greater reliability via greater use (and hence discovery of errors).
2. Inheritance- Adv & DisAdv Disadvantages:  Increased class/abstraction coupling. Program size Using large class hierarchies makes your project bigger. Dealing with the run-time dispatch of messages to objects related in an inheritance hierarchy has memory overhead. Understanding a large system (the yo-yo problem, class documentation) Inheritance means that it is not sufficient to study the header file (declaration) of a class to completely understand its behavior. You often must look up the hierarchy and consider the inherited behavior and state from its superclasses. On a practical note, this can be a pain for documentation, since you may not find the behavior you seek in the document for the class itself.
2. Inheritance – UML Notation
3. Using When a class definition uses another class as a parameter to a method, or declares an object of that class local to one of the member functions, then we say the first class is using the second. Using is not the same as aggregation, since the class being used doesn’t satisfy the whole/part question. The used class exists to help the first class.   Example: a class for calculating voltages, currents and power in an electrical circuit would need to deal with complex numbers a lot. A complex number class would be used to pass arguments to methods, hold temporary values, etc.
4. Association Classes that cooperate with each other, or are associated with each other through the model of our problem, need each others names to message back and forth. This is usually implemented in C++ by putting pointers to objects in class definitions, just like Graph had a pointer to NodeList. Association implies symmetry; both classes know each other and can message each other. A Product class object may need to know the last sale that it was involved with. We could put a pointer to a Sale class object inside the private section of Product.
4. Association A Sale class object may need to know all of the Products involved with the Sale. We can put a pointer to a pointer (double pointer) in Sale that will let us store zero or more Products associated with a Sale. Associations have a cardinality. They can be one-to-one, one-to-many, or many-to-many. Example: Each Product is part of 1 Sale; each Sale has many Products. Associations are the most generic of the relationships between classes.
4. Association A class may also represent an association between two other classes. For example, a Skill and a Person are associated with one another. A Person can have some number of Skills, and a given Skill may be associated with some set of Persons. To define the relationship, a Person-Skill class can have state such as proficiency and yearsExperience which tell how good a particular Person is at a given Skill, and how many years experience they have with it.
5. Instantiation The potential confusion for people new to OO is that instantiation is what happens to create an object, yet this is a class-to-class relationship – no objects are involved.  Another term for this relationship is “generics”. A generic class arises from a situation where the behavior of a class can be abstracted into something which is relevant to more than one type of state. The goal is to share the definition (in the class) of some behavior (i.e. the methods) across different data types. For example, a Stack class has the same fundamental behavior whether it is holding Dogs, ints, Strings, etc. We shouldn’t have to define a DogStack, IntStack, etc, as separate classes with nearly identical methods.
5. Instantiation- UML Notation An instantiation relationship is displayed in the diagram editor as a dashed line with an open arrow that points from the classifier that performs the operation to the classifier that is being instantiated. The keyword «instantiate» is attached to the connector.   In an instantiation relationship, the client model element is instantiated by the supplier element and is therefore dependent on it.

More Related Content

PPT
Class diagrams
PDF
Classes and Objects
PPTX
Class Diagram
PPTX
Chapter-4 Enhanced ER Model
PPT
Uml class-diagram
PPT
UML Diagrams
PPTX
DOCX
system sequence diagram
Class diagrams
Classes and Objects
Class Diagram
Chapter-4 Enhanced ER Model
Uml class-diagram
UML Diagrams
system sequence diagram

What's hot (20)

PPTX
object oriented methodologies
PPTX
Overview of UML Diagrams
PPTX
Object diagram
PPT
UML diagrams and symbols
PPT
Object and class relationships
PPT
State Diagrams
PDF
Object oriented software engineering concepts
PPT
Object Oriented Design
PDF
Object diagram
PPT
Object Oriented Analysis and Design
PPTX
Ooad ppt
PPTX
Sequence diagram
PPT
Slide 4 Interaction Diagram
PPTX
Type constructor
PPT
Oomd unit1
PDF
PPT
Ooad ch 2
object oriented methodologies
Overview of UML Diagrams
Object diagram
UML diagrams and symbols
Object and class relationships
State Diagrams
Object oriented software engineering concepts
Object Oriented Design
Object diagram
Object Oriented Analysis and Design
Ooad ppt
Sequence diagram
Slide 4 Interaction Diagram
Type constructor
Oomd unit1
Ooad ch 2
Ad

Similar to Object Oriented Relationships (20)

PPT
An Evolution of UML projects.and also what is project
PPT
Object oriented programming in C++ programming language
PPT
Introduction to software engineering in data science.ppt
PPT
Object oriented programming language in software engineering
PPTX
Object Oriented Principles
PDF
L ab # 07
PPTX
SAD02 - Object Orientation
PDF
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
PPT
UML DIAGRAMS FOR IST SEMISTER OF BTECH STUDENTS
PPT
Object Oriented Design
PPT
08 class and sequence diagrams
PPT
Unit 3 Java
PPT
What is OOP?
PPT
Chapter3
PDF
2 class use case
PPT
PPTX
Entity Relationship Modelling
PDF
dbms mannual.pdf
PPT
Uml - An Overview
PDF
SE_Lec 06_Object Oriented Analysis and Design
An Evolution of UML projects.and also what is project
Object oriented programming in C++ programming language
Introduction to software engineering in data science.ppt
Object oriented programming language in software engineering
Object Oriented Principles
L ab # 07
SAD02 - Object Orientation
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
UML DIAGRAMS FOR IST SEMISTER OF BTECH STUDENTS
Object Oriented Design
08 class and sequence diagrams
Unit 3 Java
What is OOP?
Chapter3
2 class use case
Entity Relationship Modelling
dbms mannual.pdf
Uml - An Overview
SE_Lec 06_Object Oriented Analysis and Design
Ad

More from Taher Barodawala (6)

PPT
Module 5 oodb systems semantic db systems
PPT
Module 3 Object Oriented Data Models Object Oriented notations
PPT
Object representations
PPT
Polygon clipping
PPTX
Bresenham circle
PPT
Hearn and Baker 2 D transformations
Module 5 oodb systems semantic db systems
Module 3 Object Oriented Data Models Object Oriented notations
Object representations
Polygon clipping
Bresenham circle
Hearn and Baker 2 D transformations

Recently uploaded (20)

PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
PPTX
Onica Farming 24rsclub profitable farm business
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
English Language Teaching from Post-.pdf
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Introduction and Scope of Bichemistry.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Cardiovascular Pharmacology for pharmacy students.pptx
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
Onica Farming 24rsclub profitable farm business
Abdominal Access Techniques with Prof. Dr. R K Mishra
Insiders guide to clinical Medicine.pdf
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
UPPER GASTRO INTESTINAL DISORDER.docx
Software Engineering BSC DS UNIT 1 .pptx
Module 3: Health Systems Tutorial Slides S2 2025
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
English Language Teaching from Post-.pdf
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx

Object Oriented Relationships

  • 1. OO Relationships DOEACC B-Level OODBMS 2011 Taher S. 3. Object Oriented Data Model
  • 2. Relationships They represent logical links between two or more entities or objects. Residence is an example of a relationship that can exist between the entities City and Employee; Exam is an example of a relationship that can exist between the entities Student and Course. An instance of a relationship is an n-tuple made up of instances of entities, one for each of the entities involved. The pair of objects made up of the employee named Johanssen and the city Stockholm, or the pair of objects made from the employee Peterson and the city Oslo, are examples of instances in the relationship Residence.
  • 4. Types of Relationships We’re going to look at the way we define the relationships between classes so we know how objects can relate to each other. Following sorts of relationships exist: Aggregation Inheritance Using Association Instantiation
  • 5. 1. Aggregation a.k.a Composition Different authors use different terms for the idea of containment. UML has a very specific use (and different symbols) of the terms aggregation and composition, though this is not necessarily consistent with OO authors.  UML aggregation is “weak containment”, usually implemented with pointers, and the symbol is an open diamond. Composition is “strong containment”, implemented by value, and the symbol is a filled diamond.
  • 6. 1. Aggregation a.k.a Composition An aggregate object is one which contains other objects. For example, an Airplane class would contain Engine, Wing, Tail, Crew objects. Sometimes the class aggregation corresponds to physical containment in the model (like the airplane). But sometimes it is more abstract (e.g. Club and Members).   The test for aggregation is to see if there is a whole/part relationship between two classes (“hasa”). A synonym for this is “part-of”.
  • 7. 2. Inheritance- Terminology When we use inheritance, we have classes at the top of the hierarchy that are known variously as: Generalization Parent Superclass Base Abstract And classes at the bottom of the hierarchy (or those which inherit from some other class) known variously as: Specialization Child Subclass Derived Concrete
  • 8. 2. Inheritance The classes toward the top of an inheritance hierarchy tend to be abstract classes that won’t have any objects instantiated from them. The bottom most classes of the hierarchy are the concrete classes from which we actually make objects that do work for us.
  • 9. Inheritance- Generalizations & Specializations Generalizations represent logical links between an entity E, known as parent entity, and one or more entities E1,...,En called child entities, of which E is more general, in the sense that they are a particular case. In this situation we say that E is a generalization of E1,...,En and that the entities E1,...,En are specializations of E.
  • 10. 2. Inheritance- Generalizations & Specializations
  • 11. Generalization- Types A generalization is total if every instance of the parent entity is also an instance of one of its children, otherwise it is partial. A generalization is exclusive if every instance of the parent entity is at most an instance of one of the children, otherwise it is overlapping. The generalization Person, of Man and Woman is total (the sets of men and the women constitute ‘all’ the people) and exclusive (a person is either a man or a woman). The generalization Vehicle of Automobile and Bicycle is partial and exclusive, because there are other types of vehicle (for example, motor bike) that are neither cars nor bicycle. The generalization Person of Student and Employee is partial and overlapping, because there are students who are also employed.
  • 13. 2. Inheritance- Adv & DisAdv Advantages: Avoid redundant code by sharing it between classes: Inheritance relationships let us avoid the redundancy of declaring the same instance variables and behavior in a group of related classes. For instance, Dogs and Cats don’t both need a name variable; they can inherit it from Pet. Enforcing standards at a design level (interfaces) Programming-by-drag-and-drop (components) Avoid redundant code by sharing it between projects (reuse)Shared code allows for rapid prototyping via reuse. Shared code produces greater reliability via greater use (and hence discovery of errors).
  • 14. 2. Inheritance- Adv & DisAdv Disadvantages: Increased class/abstraction coupling. Program size Using large class hierarchies makes your project bigger. Dealing with the run-time dispatch of messages to objects related in an inheritance hierarchy has memory overhead. Understanding a large system (the yo-yo problem, class documentation) Inheritance means that it is not sufficient to study the header file (declaration) of a class to completely understand its behavior. You often must look up the hierarchy and consider the inherited behavior and state from its superclasses. On a practical note, this can be a pain for documentation, since you may not find the behavior you seek in the document for the class itself.
  • 15. 2. Inheritance – UML Notation
  • 16. 3. Using When a class definition uses another class as a parameter to a method, or declares an object of that class local to one of the member functions, then we say the first class is using the second. Using is not the same as aggregation, since the class being used doesn’t satisfy the whole/part question. The used class exists to help the first class.   Example: a class for calculating voltages, currents and power in an electrical circuit would need to deal with complex numbers a lot. A complex number class would be used to pass arguments to methods, hold temporary values, etc.
  • 17. 4. Association Classes that cooperate with each other, or are associated with each other through the model of our problem, need each others names to message back and forth. This is usually implemented in C++ by putting pointers to objects in class definitions, just like Graph had a pointer to NodeList. Association implies symmetry; both classes know each other and can message each other. A Product class object may need to know the last sale that it was involved with. We could put a pointer to a Sale class object inside the private section of Product.
  • 18. 4. Association A Sale class object may need to know all of the Products involved with the Sale. We can put a pointer to a pointer (double pointer) in Sale that will let us store zero or more Products associated with a Sale. Associations have a cardinality. They can be one-to-one, one-to-many, or many-to-many. Example: Each Product is part of 1 Sale; each Sale has many Products. Associations are the most generic of the relationships between classes.
  • 19. 4. Association A class may also represent an association between two other classes. For example, a Skill and a Person are associated with one another. A Person can have some number of Skills, and a given Skill may be associated with some set of Persons. To define the relationship, a Person-Skill class can have state such as proficiency and yearsExperience which tell how good a particular Person is at a given Skill, and how many years experience they have with it.
  • 20. 5. Instantiation The potential confusion for people new to OO is that instantiation is what happens to create an object, yet this is a class-to-class relationship – no objects are involved.  Another term for this relationship is “generics”. A generic class arises from a situation where the behavior of a class can be abstracted into something which is relevant to more than one type of state. The goal is to share the definition (in the class) of some behavior (i.e. the methods) across different data types. For example, a Stack class has the same fundamental behavior whether it is holding Dogs, ints, Strings, etc. We shouldn’t have to define a DogStack, IntStack, etc, as separate classes with nearly identical methods.
  • 21. 5. Instantiation- UML Notation An instantiation relationship is displayed in the diagram editor as a dashed line with an open arrow that points from the classifier that performs the operation to the classifier that is being instantiated. The keyword «instantiate» is attached to the connector.   In an instantiation relationship, the client model element is instantiated by the supplier element and is therefore dependent on it.