Top Banner
Winter 2007 ACS-3913 Ron McFa dyen 1 Classes Represented by a rectangle with possibly 3 compartments Customer Customer Name Address Customer Name Address getName() checkCreditRating() Customer getName() checkCreditRating()
27

Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 1

Classes

Represented by a rectangle with possibly 3 compartments

Customer

Customer

NameAddress

Customer

NameAddress

getName()checkCreditRating()

Customer

getName()checkCreditRating()

Page 2: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 2

Classes

«Singleton»dbFacade

Some classes are stereotyped:

Later in the course we study the Singleton design pattern.

Some methodologies have 3 stereotypes for “analysis” classes: boundary, control, entity

Page 3: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 3

Class Diagram

Navigability

In the example below, student could be implemented with a history attribute:

Student History *

-history[0..*] : History

history[0..*] provides for the association to be navigated – we can send a message to a History object

Page 4: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 4

Instances

Joe: Customer

Class instances

An individual object (instance of a class) is shown with naming information underlined

An unnamed customer: Customer

A customer named Joe

Page 5: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 5

Diagramming notation

:sale

s4:sale

A sale object named s4

An unnamed sale object

s4

An object named s4

Sale

The class Sale

Page 6: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 6

Attributes

an object contains data which are defined as part of the Class definition

examples:• Students have names, addresses, etc; • Courses have titles, descriptions, prerequisite information.

Rectangle

corner: Point

Student

nameaddress

Level of detail present will depend on whether you are in analysis or design, and your purposes at the time

Page 7: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 7

Attributes

To what degree is an attribute visible to other classes?Private –Public +Protected #Package ~

Student

-name-address

Page 8: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 8

Attributes

Default values =Derived values /Multiplicity [ ]Ordering {ordered}Uniqueness {unique}

Invoice

-date:Date = today-/total: Currency-payments[0..*]: Currency

Student

-name-address[1..3] {unique}

Page 9: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 9

Operations. What are the responsibilities of a class? What can it do?

Visibility

Parameters

Signature the name, parameters, and return type of the operation

Student

+getName()+getGPA(term :Term, gpaType: String)

Page 10: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 10

Associations

• correspond to verbs expressing a relationship between classes

• example a Library Member borrows a Copy of a Book

•Multiplicities• we indicate via multiplicities the range of allowable cardinalities for participation in an association• examples: 1, 1..*, 0..*, 1..3

Page 11: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 11

Associations

• Names and roles

• you can name the relationship and indicate how to read it• you can give role names for participating objects

Person CompanyWorks for1..* 1

employer employee

The role of a Person in this relationship The role of a Company in this relationship

The name of the relationship and thedirection for reading the name

Page 12: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 12

Associations

•example: a Library Member borrows a Copy of a Book

Member Book* *

borrowerborrows

Page 13: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 13

Associations

• example: An employee is supervised by an employee

*

0,1Employee

reports to

supervised

supervisor

A reflexive association

Page 14: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 14

Interfaces

An interface is special type of class that cannot be instantiated. An application can never instantiate an interface.

An interface defines a set of public attributes and operations that some class must use (depends on)

There is no behaviour defined, no method coded

Some other class inherits the interface and provides the implementation

Page 15: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 15

From Head First …

package headfirst.observer.weatherobservable;import java.util.Observable;import java.util.Observer;

public class ForecastDisplay implements Observer, …

public void update(Observable observable, Object arg) {if (observable instanceof WeatherData) {

WeatherData weatherData = (WeatherData)observable;lastPressure = currentPressure;currentPressure = weatherData.getPressure();display();

}}public void display() {

System.out.print("Forecast: ");if (currentPressure > lastPressure) {

System.out.println("Improving weather on the way!");} …

Page 16: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 16

From Head First …

package headfirst.observer.weatherobservable;

import java.util.Observable;import java.util.Observer;

public class StatisticsDisplay implements Observer, DisplayElement {private float maxTemp = 0.0f;

…public void update(Observable observable, Object arg) {

if (observable instanceof WeatherData) {WeatherData weatherData = (WeatherData)observable;float temp = weatherData.getTemperature();…

display();}

}public void display() {

System.out.println("Avg/Max/Min temperature = " …

Page 17: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 17

From Head First …

<<interface>>Observer

ForecastDisplay

update()

These classes implement the update operation

StatisticsDisplay

Page 18: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 18

Sequence Diagram

•Objects are represented horizontally across the top of the diagram

•Each object has a lifeline

•some exist before and/or after

•some are created during

•some are destroyed during

•An active object is indicated by a narrow rectangle

•Focus of control

•Time is represented vertically down the diagram. Time moves forward as you go downwards

•Iteration is shown with a frame

Page 19: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 19

Sequence Diagram

Message types

•Synchronous

•Asynchronous

•Creation

•Reply

SynchronousA message from one object to another object, and where the first object must wait until the resulting action completes.ReplyRepresents an explicit return of control. Not often used.

Page 20: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 20

: register : sale

: payment

makePayment()

makePayment()payment()

sd Make payment

Sequence Diagram named Make payment

Object is created

Page 21: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 21

X

: register : sale

: payment

makePayment()

makePayment()payment()

sd Make Payment

Object is destroyed

Page 22: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 22

Message to ‘self’

A reflexive message

: sale

calcTotal()getTotal()

Page 23: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 23

Iteration

:Sale :SalesLineItem

t=getTotal()

st = getSubTotal()loop [I < numItems]

loop is one of the keywords you can use to specify the nature of the fragment

Page 24: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 24

client

getInstance()alt

Behaviour in Singleton Pattern

:CarMatchOfficeCarMatchOffice()

Inst=CarMatchOffice()

getInstance()

[inst == null]

[else]

getAddress()

When you ask for the instance of CarMatchOffice, there are two ways it can complete. CarMatchOffice

Page 25: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 25

Collaborations

Collaboration : an arrangement of classes, links, roles in a context to implement some behaviour.

Useful for showing a system’s applications of patterns.

Name of pattern appears in a dashed oval.

Links to classes shown with participation roles.

The value of using collaborations on your class diagram is to show what patterns you have used and the roles that classes and objects will be playing.

Page 26: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 26

Weather Station Class Diagram

«interface»

Subject

attach()

detach()

notify()

«interface»

Observer

update()

WeatherDataattach()detach()notify()

CurrentConditionsDisplayupdate()display()

*

StatisticsDisplayupdate()display()

ForecastDisplayupdate()display()

«interface»

DisplayElement

display()

Page 27: Winter 2007ACS-3913 Ron McFadyen1 Classes Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName()

Winter 2007 ACS-3913 Ron McFadyen 27

Class Diagram showing Observer Collaboration

«interface»

Subject

attach()

detach()

notify()

«interface»

Observer

update()

WeatherDataattach()detach()notify()

CurrentConditionsDisplayupdate()display()

*

StatisticsDisplayupdate()display()

ForecastDisplayupdate()display()

«interface»

DisplayElement

display()

Observer

subject obse

rver

Con

cret

e su

bjec

t

Concrete observer

Concrete observer

Concrete observer