Lecture20 - Object Oriented Design and UML Class...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Object Oriented Design and UML Class Relationships Dependency Aggregation Inheritance Interfaces Reading for this Lecture: L&L 6.4 – 6.5
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Class Relationships Classes in a software system can have various types of relationships to each other Three of the most common relationships: Dependency: A uses B Aggregation: A has-a B Inheritance: A is-a B We cover dependency and aggregation now We cover inheritance later
Background image of page 2
3 Dependency A dependency exists when one class relies on another in some way, usually by invoking the methods of the other We've seen dependencies in many previous examples We don't want numerous or complex dependencies among classes Nor do we want complex classes that don't depend on others A good design strikes the right balance
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Dependency Some dependencies occur between objects of the same class A method of the class may accept an object of the same class as a parameter For example, the concat method of the String class takes as a parameter another String object str3 = str1.concat(str2); This drives home the idea that the service is being requested from a particular object
Background image of page 4
5 Dependency The following example defines a class called Rational to represent a rational number A rational number is a value that can be represented as the ratio of two integers Some methods of the Rational class accept another Rational object as a parameter See RationalTester.java (page 297) See Rational.java (page 299)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Aggregation An aggregate is an object that is made up of other objects Therefore aggregation is a has-a relationship A car has a chassis and has an engine In software, an aggregate object contains references to other objects as instance data The aggregate object is defined in part by the objects that make it up This is a special kind of dependency – the aggregate usually relies for its existence on the objects that compose it
Background image of page 6
Aggregation In the following example, a StudentBody object is composed of Student objects which depend on Address objects A StudentBody has one or more Student (s) See StudentBody.java (page 304) See Student.java (page 306) See Address.java (page 307) An aggregation association is shown in a UML
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 24

Lecture20 - Object Oriented Design and UML Class...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online