Presentation is loading. Please wait.

Presentation is loading. Please wait.

Other Class and Object Relationships

Similar presentations


Presentation on theme: "Other Class and Object Relationships"— Presentation transcript:

1 Other Class and Object Relationships
Chapter 12 Other Class and Object Relationships Marilyn Bohl/Maria Rynn Tools for Structured and Object-Oriented Design, 7e © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.

2 Introduction The world is filled with objects.
A carnation is a kind of flower. A daisy is a kind of flower. A rose is a kind of flower. A yellow rose is a kind of rose. A white rose is a kind of rose. A rose petal is a part of a rose. A thorn is a part of a rose. A vase holds one or more flowers. A watering gives water to one or more flowers.

3 Introduction Roses, daisies, and carnations are all subclasses of flowers. Classes have relationships with other classes (and objects) that are different than generalization/specialization relationships.

4 Class Diagram--Generalization/Specialization

5 Association Association
Connections among objects (instances) of classes. Objects of different classes can interact. Binary association Association between a pair of classes. Represented by a line or path, connects participating classes.

6 Association—Example 1: WorksFor

7 Association Role names identify an association end and support navigation from one object to another using the association. Person1.employer Self-association an association involving the same class more than once role names are necessary to identify the association ends attached to the same class.

8 Association Asterisk (*)
Zero or more, without limit. The symbol 1...* is one or more, without limit. Multiplicity—how many instances of one class is the association relationship can be related to one instance of the other class in the relationship. An instance of an association is a link.

9 Example of Multiplicity

10 Sample Problem 12.1 Vases and Flowers
Tracking flowers in vase for a local nursery that sells floral arrangements to customers. A vase holds one or more flowers. 0..1 symbol indicates that a flower might not be contained in a vase at all.

11 Aggregation Aggregation, or whole-part relationship is between an aggregate (a whole) and a part. “has-a” relationship UML an unfilled diamond symbol. Other end—the part—is unmarked.

12 Aggregation—Example 1

13 Aggregation—Example 2

14 Managing Assets Example
The aggregate may send messages to its parts during processing. A part can communicate with its aggregate during processing. A single UML, class diagram may show multiple types of relationships.

15 Class Diagram—Multiple Relationships Example

16 A Frame for Measurement Conversion

17 Composition—Exchange 1

18 Composition—Exchange 1 cont.

19 Composition Solid-filled diamond symbols indicate composition relationships. Composition is a form of aggregation relationship in which two additional rules apply: 1—An object may be a part of only one composite at a time. 2—a composite has sole responsibility for the disposition of its parts. The composite is responsible for their creation and destruction.

20 Composition During instantiation, a composite must ensure that all parts have been instantiated and correctly assigned to it. During the life of the composite no other composite may have responsibility for the part without the composite's concurrence.

21 Composite—Example 2

22 Iterative Design The relationships between the classes are aggregations The aggregation relationships are compositions. Iterative design Looking again at our work in progress to improve it or add to it as our understanding of the problem situation increases.

23 Sample Problem 12.2 Planning a Group Event
Honor society planning the annual induction ceremony and dinner for new members.

24 Class Diagram—Event Planning Problem

25 Inner Classes Inner class Define a class within another class
Defined within another class (the enclosing class)‏ Define a class within another class When the inner class makes sense only in the context of its enclosing class When it relies on the enclosing class for its function. Sometimes the use of an inner class stems from a desire for programming convenience.

26 Inner Classes Java inner class has access to all of the enclosing class's members, even if they are declared private. The modifiers restrict access by classes outside the enclosing class but not by classes inside it.

27 MonthlyInventory Class with Inner Class WriteExcep Pseudocode

28 MonthlyInventory Class with Inner Class WriteExcep Pseudocode cont.

29 MonthlyInventory Class with Inner Class WriteExcep Pseudocode cont.

30 Inner Classes An inner class has no separate existence outside of the class that encloses it.

31 Benefits of Object-Oriented Design
Simpler maintenance Resilient to change Changes can be made without invalidating the current design and without having unforeseen “side effects” on other parts of the applications. Higher productivity Class libraries contain many prebuilt (and thus working and tested) classes. Encourages and facilitates reuse not only of software but also of entire designs.

32 Benefits of Object-Oriented Design
The availability of well-tested, proven components means less overall new work to be done on a project. Encourages the developer to work within a scope that he or she can handle easily.


Download ppt "Other Class and Object Relationships"

Similar presentations


Ads by Google