Top Banner
Fall 2009 ACS-3913 Ron McFa dyen 1 Class Represented by a rectangle with possibly 3 compartments Customer Customer Name Address Customer Name Address getName() checkCreditRating() Customer getName() checkCreditRating() Class name attributes operations operations attributes Class name Class name Class name
21

Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Jan 03, 2016

Download

Documents

Darren Palmer
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: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 1

Class

Represented by a rectangle with possibly 3 compartments

Customer

Customer

NameAddress

Customer

NameAddress

getName()checkCreditRating()

Customer

getName()checkCreditRating()

Class name

attributes

operations

operations

attributes

Class nameClass name

Class name

Page 2: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 2

Class

«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: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 3

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 4: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 4

Attributes

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

Student

-name-address

Page 5: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 5

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 6: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 6

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 7: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 7

Associations

• correspond to verbs expressing a relationship between classes

• example a Library Member borrows a Copy of a Book

•Navigability•A directed association show that messages will be sent in that direction

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

Page 8: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 8

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 9: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 9

Associations

•example: A duck uses a flying behavior

Duck FlyBehavior1uses

Page 10: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 10

Associations

• example: An employee is supervised by an employee

*

0,1Employee

reports to

supervised

supervisor

A reflexive association: an instance of this association involves two Employee objects (two objects from the same class).

Page 11: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 11

Inner Class

SwingObserverExample AngelListener Angel listens to

DevilListener Devil listens to

+

+

+It is common to use to indicate an inner class

Page 12: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 12

Navigability

The association below is directed. The arrow indicates the direction in which messages are sent. Note this means that a duck will “know” its flying behaviour. In the implementation of a duck there is need for an attribute that is a reference to a flying behaviour object.

Duck FlyBehavior 1uses

Page 13: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 13

Navigability:

An association line with a navigability adornment indicates that an object of one class (A) is connected uni-directionally to an object of another class (B)

An object of class A can navigate to an object of class B.

•I.e. an object of class A needs to know the B object, but not the other way around.

•An instance of A can send a message to an instance of B, the instance can respond, but doesn’t initiate.

An association line that has no specific navigation indicated, is considered to be bi-directional

In an OO language,

an A will have an

attribute that

references a B instance

A

b: B

B

Page 14: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 14

Association Class

Business rule: a person contracts their services to a company

Association Class: a modeling element that is both an association and a class. It has attributes, operations, multiplicities, etc. It can participate in other relationships. Note the dashed line.

Company Person

Contract

startDate

* *

Page 15: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 15

Many to many associations

•likely candidate for an Association Class

Limitation: each company object can be associated to a person object only once. If we wanted to provide for a person to be contracted to the same company more than once, we would need to promote Contract to be a regular class. How do we model this?

Company Person

Contract

startDate

* *

Page 16: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 16

Reflexive Association

An association involving the same class more than once.

marries

Person1

1

marries

Person*

*

?

Page 17: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 17

Reflexive Association

An association involving the same class more than once.

comprises

Part*

*

Page 18: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 18

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 (generalization, inheritance)

Page 19: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 19

Interfaces

<<interface>>FlyBehavior

FlyNoWay

fly()

These classes implement the fly operation

FlyWithWings

fly() fly()

The interface named FlyBehavior comprises the fly operation

Page 20: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 20

Abstract Classes

An abstract class is a special type of class in a class hierarchy that cannot be instantiated. An application can never instantiate an abstract class and so must instantiate objects at a more specialized level in the hierarchy.

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

If an operation is not abstract, then its behaviour is defined in the abstract class, i.e. there is an implementation, but this may be overriden in a more specialized subclass.

Page 21: Fall 2009ACS-3913 Ron McFadyen1 Class Represented by a rectangle with possibly 3 compartments Customer Name Address Customer Name Address getName() checkCreditRating()

Fall 2009 ACS-3913 Ron McFadyen 21

Abstract Classes

Duck

RubberDuck

performfly()swim()display()

The swim operation is overridden in RubberDuck.

Both subclasses have implementations of display().

MallardDuck

display() swim()display()

The abstract class has its name in italics.

The performFly() and swim() operations are defined, but display() is not defined (it is an abstract operation)