+ All Categories
Home > Documents > Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design...

Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design...

Date post: 19-Dec-2015
Category:
View: 215 times
Download: 0 times
Share this document with a friend
Popular Tags:
21
Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus
Transcript
Page 1: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Copyright © 2012 Pearson Education, Inc.

UML

Java Software SolutionsFoundations of Program Design

Seventh Edition

John LewisWilliam Loftus

Page 2: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Unified Modeling Language• A graphical language used for designing programs

– http://www.uml.org

• UML for short• Used for illustrating the relationships that exist

among classes in a program• There are several kinds of UML diagrams

– Class diagrams– Object diagrams– Collaboration diagrams– Sequence diagrams

Page 3: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Class Diagrams• Use a box to represent a class• Use lines between the classes to represent the

relationships between them• The box representing a class is divided into up to

three sections– The name of the class goes in the top– The instance variables are listed in the middle section– The methods are listed in the bottom section

• Member visibility represented by a symbol+ for public- for private- # for protected

Page 4: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Example Class Diagram

Copyright © 2012 Pearson Education, Inc.

Page 5: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Dependency• A dependency exists when one class relies on

another in some way, usually by invoking the methods of the other

• We say the dependent class uses the class it depends on

• A driver class (main class) always uses other classes

• Use a dashed arrow to represent the uses relationship

– Arrow points to the class being used

Copyright © 2012 Pearson Education, Inc.

Page 6: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Class Diagram for Pig Latin

PigLatin

+ main (args : String[]) : void

+ translate (sentence : String) : String- translateWord (word : String) : String- beginsWithVowel (word : String) : boolean- beginsWithBlend (word : String) : boolean

PigLatinTranslator

Copyright © 2012 Pearson Education, Inc.

Page 7: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Aggregation

• An aggregate is an object that is made up of other objects

– An aggregate object contains references to other objects as instance data

• Therefore aggregation is a has-a relationship

• This is a special kind of dependency; the aggregate relies on the objects that compose it

• Use a solid line with an open diamond to represent has-a

– Diamond is next to the containing classCopyright © 2012 Pearson Education, Inc.

Page 8: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Aggregation in UML

StudentBody

+ main (args : String[]) : void

+ toString() : String

Student- firstName : String- lastName : String- homeAddress : Address- schoolAddress : Address

+ toString() : String

- streetAddress : String- city : String- state : String- zipCode : long

Address

Copyright © 2012 Pearson Education, Inc.

Page 9: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Inheritance

• Inheritance relationships are shown in a UML class diagram using a solid arrow with an unfilled triangular arrowhead pointing to the parent class

Vehicle

Car

• Proper inheritance creates an is-a relationship, meaning the child is a more specific version of the parent

Copyright © 2012 Pearson Education, Inc.

Page 10: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Abstract classes

• Use abstract for the stereotype to show a class is abstract

4-10

Page 11: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Class Diagram for Words

Book

# pages : int

+ pageMessage() : void

Dictionary

- definitions : int

+ definitionMessage() : void

Words

+ main (args : String[]) : void

Copyright © 2012 Pearson Education, Inc.

Page 12: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Class Hierarchies

• Sometimes we only want to show a class hierarchy– Leave out most of the detail

Copyright © 2012 Pearson Education, Inc.

Page 13: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Interfaces

• Implementing an interface also creates an is-a relationship

• Use a dashed arrow with an outlined triangular head

• Use interface for the stereotype

4-13

Page 14: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Spring 2011

CS 225 14

UML Symbols

Symbol Visibility

+ public

- private

# protected

~ package

Relationship Connector

inheritance (is-a)

open arrow

association (uses)

solid line

aggregation/composition(has-a)

open/ soliddiamond

inner class circle with cross

Page 15: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Object Diagrams• These diagrams are used to represent the state of

the program at some time while it is running– The state changes as the program runs

• Represent an object with a box– The type of the object is underlined– The box contains other boxes to hold the instance data

Copyright © 2012 Pearson Education, Inc.

Page 16: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Object diagram

• An object is also represented as a box

• The name of the object (optional) and the name of the class are underlined

• Attribute values may be shown

4-16

Page 17: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Object Diagrams• There are several kinds of diagrams that show the

objects in a program and how they interact– Object diagrams show the state of the objects at a

particular point in the program– Collaboration diagrams show the interactions between

objects by showing method calls– Sequence diagrams show interactions between objects

as a function of time

4-17

Page 18: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Object Diagram

Copyright © 2012 Pearson Education, Inc.

Page 19: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Collaboration Diagram

• Shows interactions (e.g. method calls) between objects

• Active object is bold

4-19

Page 20: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Sequence Diagram

• Show interactions between objects as a function of time

• Time axis goes down

4-20

Page 21: Copyright © 2012 Pearson Education, Inc. UML Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus.

Spring 2011

CS 225 21

Tools for UML Diagrams• On onyx

– dia– umbrello– violet

• There are also Eclipse plug-ins but they are usually not open-source– Some of these can build code from the UML diagram


Recommended