Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Architectures

Similar presentations


Presentation on theme: "Software Architectures"— Presentation transcript:

1 Software Architectures
Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State University One Washington Square San José, CA © M.E. Fayad SJSU -- CmpE

2 Lesson 4-5: Relationships
2 © M.E. Fayad SJSU -- CmpE M.E. Fayad

3 3 Lesson Objectives Discuss UML Associations Discuss UML – aggregation
Understand UML- inheritance Understand How to identify UML Artifacts 3 © M.E. Fayad SJSU -- CmpE M.E. Fayad

4 4 Relationships A relationship is a connection among things
Three most important relationships in OO dependencies generalizations associations Different kind of lines are used to distinguish various kinds of relationships 4 © M.E. Fayad SJSU -- CmpE M.E. Fayad

5 5 Dependencies (1) Dependencies are using relationships
State that a change in specification of one thing (the supplier) may affect another thing that uses it (the client), but not necessary the reverse Graphically, it is rendered as a dashed directed line 5 © M.E. Fayad SJSU -- CmpE M.E. Fayad

6 6 Dependencies (2) Dependent Class Independent Class Client Supplier
Order Book © M.E. Fayad SJSU -- CmpE M.E. Fayad

7 Associations (1) An association shows a two-way relationship between objects (instances) of two or more classes and requiring special implementation to ensure integrity. A particular instance of an association is often called a link. Associations between classes are required if the objects need to communicate. Associations are often named, and have role-names for each side of the link. 7 © M.E. Fayad SJSU -- CmpE M.E. Fayad

8 8 Types of Association Unary association Binary association
both ends of an association circle back to the same class Binary association an association that connects exactly two classes N-ary association an association that connects more than two classes 8 © M.E. Fayad SJSU -- CmpE M.E. Fayad

9 Associations (2) Name an association can have a name, and the name is used to describe the nature of the relationship Role when a class participates in an association, it has a specific role that it plays in that relationship a role is just the face the class at the near end of the association presents to the class at the other end of the association 9 © M.E. Fayad SJSU -- CmpE M.E. Fayad

10 10 Associations (3) Association Name Car Person Vehicle Registration
model year # of doors name age address registeredCar owner Roles Names 10 © M.E. Fayad SJSU -- CmpE M.E. Fayad

11 11 Associations (4) Multiplicity Name Owns by employee employer
1..* * Person Company employee employer 11 Role Name © M.E. Fayad SJSU -- CmpE M.E. Fayad

12 12 More on Associations Simple example:
An association has a name and a numerical specification (multiplicity indication) of how many objects on one side of the association are connected with how many objects on the other side. Associations are called use relationships – even if this may seem somewhat cheeky in the example below displays 0..* Window GeomFigure employs 0..* Company Person 12 Employer Employee © M.E. Fayad SJSU -- CmpE M.E. Fayad

13 More on Associations Associations are directed (one way), bidirectional, and undirected. UML makes no distinction between bidirectional and undirected associations. Multiplicity Stereotype RelationName {Constraints} * Class1 Class2 13 role1 Role2: interface © M.E. Fayad SJSU -- CmpE M.E. Fayad

14 More on Associations Recursive association: A class has a relation with itself. It is also possible to model associations that are valid only temporarily “stereotype or temporary” Constraints may be used to restrict the relation under specific aspects. A role name describes how the object is seen by the opposite object in the association. An association can be described in more detail by means of constraints, tagged values, and stereotypes. Stereotypes are noted before or above the relation name, constraints, and tagged values after or below the name. 14 © M.E. Fayad SJSU -- CmpE M.E. Fayad

15 More on Associations Directed association is a one-way association, in which one side knows the other, but not vice versa. Multiplicity Specification: 1 exactly one 0, 1 zero or one 0..4 between zero and four 3, 7 either three or seven 15 © M.E. Fayad SJSU -- CmpE M.E. Fayad

16 16 More on Associations More multiplicity specifications:
0..* greater than or equal to zero (default) * ditto 1..* greater than or equal to one 0..3, 7, 9..* between zero and three, or exactly seven, or greater than or equal to nine. 16 © M.E. Fayad SJSU -- CmpE M.E. Fayad

17 17 More Multiplicities Multiplicity
how many objects may be connected across an instance of an association can be a range of values or an explicit value exactly one 1 zero or one (optional) zero or more (many) 0..* one or more (mandatory) 1..* numerically specified m..n 17 © M.E. Fayad SJSU -- CmpE M.E. Fayad

18 More on Associations Recursive associations are associations in which one class is involved. has Patient Employee name staffNo roomNo office clerk relative * * 1 manager Person leads 18 reports to © M.E. Fayad SJSU -- CmpE M.E. Fayad

19 N-ary Association An n-ary association is like a common (binary) association, except that more than two association roles involved in it. N-ary association Class1 Class2 Ternary association 19 Class3 © M.E. Fayad SJSU -- CmpE M.E. Fayad

20 More on n-ary Association
Reservation Seat Train 1..* 1 carriageNo seatNo date trainNo 1..* Passenger name title Ternary association 20 © M.E. Fayad SJSU -- CmpE M.E. Fayad

21 21 More on Associations N-ary Associations
Recursive Associations N-ary Associations Attributed Associations (Association Class) Association Constraints Qualified Associations Derived Associations Directed Associations Ordered Associations Realization/Refinements Dependency 21 © M.E. Fayad SJSU -- CmpE M.E. Fayad

22 22 More on Associations Associations are usually bidirectional
Allows each object involved in the relationship to refer to the object to which it is related. Bidirectional association means at the relationship has an inverse. Associations do not have to be bidirectional. 22 © M.E. Fayad SJSU -- CmpE M.E. Fayad

23 23 Association Type One-to-One One-to-Many (One-to-Zero-or-More)
Marriage Woman Association Type One-to-One One-to-Many (One-to-Zero-or-More) Many-to-Many Zero or One husband wife Screen Windows Window Nets Authorization User Car Trailer 23 © M.E. Fayad SJSU -- CmpE M.E. Fayad

24 24 Association Type Specified the # of instances on the “many” side
Specify the possible # of instances using “or” Ternary relationship Square Sides Line Secure Room Occupants Person TraditionalFamily Male Female father mother children 24 Child © M.E. Fayad SJSU -- CmpE M.E. Fayad

25 25 Association Class Connection Connection
Server Connection Client Connection baudRate protocol wireType disconnect rerouteLink • These attributes don’t belong in either the Client or Server class. • They are attributes of the connection itself. 25 • The association class can have behaviors as well as attributes. © M.E. Fayad SJSU -- CmpE M.E. Fayad

26 Aggregation & Composite
Aggregation is a special form of association. Aggregation is used when the relationship is “part/whole” or “contains/is-part-of” Aggregation is transitive and operations on “whole” often cascade down to “parts”. 26 © M.E. Fayad SJSU -- CmpE M.E. Fayad

27 Aggregation & Composite
Computer Server Aggregation “whole” “part” 52 * Client CPU Disk Drive Keyboard Mouse 27 © M.E. Fayad SJSU -- CmpE M.E. Fayad

28 Aggregation & Composite
Special diamond symbol used on “whole” side to indicate aggregation. Aggregation is an anti-symmetric that is, if A is part of B, then B is not part of A. DO NOT confuse aggregation with generalization An essential property of aggregates is that the whole acts as a proxy for its parts. A composition is a strict form of aggregation, in which the parts are existence-dependent on the entirely 28 © M.E. Fayad SJSU -- CmpE M.E. Fayad

29 29 Aggregation Whole Anywhere from four to many Part Car Body Motor
1 1 1 1 1 4..* Body Motor Wheel 29 Part © M.E. Fayad SJSU -- CmpE M.E. Fayad

30 Aggregation & Composite
Part Entirely Composition Existence- DependentPart 30 © M.E. Fayad SJSU -- CmpE M.E. Fayad

31 Aggregation Problem Mr. Clinton’s hand is part-of Mr. Clinton & Mr. Clinton is part-of U.S.A. Therefore: Mr. Clinton’s hand is part-of U.S.A. 31 © M.E. Fayad SJSU -- CmpE M.E. Fayad

32 32 Cash Register Example Keypad * Number Keys Total Key Subtotal Key
display display display drawer Display Drawer 32 © M.E. Fayad SJSU -- CmpE M.E. Fayad

33 Attributes Attributes are simply the information associated with the object. The data type used to hold the attributes is often a fundamental type, such as int or char. Sometimes the attribute can be a non-fundamental type, such as String type and Address type. Avoid using attributes which might be better implemented as an association to a new class. 33 © M.E. Fayad SJSU -- CmpE M.E. Fayad

34 34 More on Attributes * For example: x Using Association
Using Attributes Using Association TV TV Manufacturer String model String serialNum String manName String model String serialNum product manu- facturer String name Address address * Why? Using an association to a Manufacturer class, the name and address of each manufacturer will be stored in one place rather than in each of the TV objects made by that manufacturer. 34 © M.E. Fayad SJSU -- CmpE M.E. Fayad

35 35 More on Attributes Employee Employee Split into two classes
If attributes only make sense in some instances of a given class but not in others. It will make sense to split the single class into two classes or more. Employee String name float salary Employee Split into two classes String name float salary long clearanceNum inheritance ClearedEmployee 35 long clearanceNum openVault() • Not all employees have clearances © M.E. Fayad SJSU -- CmpE M.E. Fayad

36 Generalization (1) A relationship between a general thing (called the superclass or parent) and a more specific kind of that thing (called the subclass or child) also known as the “is-a-kind-of” relationship A child is substitutable for the parent inherits the properties of its parents 36 © M.E. Fayad SJSU -- CmpE M.E. Fayad

37 37 Generalization (2) A class Inheritance
may have zero, one, or more parents that has no parents and has one or more children is called a root class or a base class that has no children is called a leaf class Inheritance a class with exactly one parent uses single inheritance a class with more than one parent uses multiple inheritance Graphically, it is rendered as a solid directed line with a large open arrowhead, pointing to the parent 37 © M.E. Fayad SJSU -- CmpE M.E. Fayad

38 Inheritance When a relationship exists between classes such that lower-level classes (called subclasses) share certain attributes and behaviors which can be defined once in a higher-level class (called superclasses). Subclasses inherit properties (attributes and behaviors) of its superclass and then adds its own unique properties and modifies any inherited properties. This is called Generalization or Inheritance. 38 © M.E. Fayad SJSU -- CmpE M.E. Fayad

39 39 Base and Leaf Classes Base Class Leaf Class Account Bank book
Checking Loan Leaf Class 39 © M.E. Fayad SJSU -- CmpE M.E. Fayad

40 40 More on Inheritance Window paintWindow size bitmaps icon textWindow
contents 40 © M.E. Fayad SJSU -- CmpE M.E. Fayad

41 Single and Multiple Inheritance
Account Loan Checking Bank book Service Passenger Car Private Car Taxi Single inheritance Multiple inheritance 41 © M.E. Fayad SJSU -- CmpE M.E. Fayad

42 Aggregation vs. Inheritance
Aggregation Inheritance Instances of distinct classes Instances of a single class “a-part-of” (APO) “a-kind-of” or “is-a” (AKO) Contains superclass-of Aggregate + parts Superclass + subclass “and” relationship “or” relationship Propagated only if specified Inheritance 42 © M.E. Fayad SJSU -- CmpE M.E. Fayad

43 Discussion Questions What are the other terms for attributes & operations? Define an object and a class in UML What is an association? Give examples Associations are usually bidirectional. Please describe. Describe the basic difference between aggregation and inheritance. What do they have in common? What do you think “multiple inheritance” means? Which type of association is more likely to yield savings in the amount of code required for implementation? why? Define the process of identifying objects, classes, inheritance, associations & aggregation, attributes, and behaviors Define Polymorphism with examples What do we mean by saying “Model/View/Controller”? 43 © M.E. Fayad SJSU -- CmpE M.E. Fayad


Download ppt "Software Architectures"

Similar presentations


Ads by Google