1 object-oriented programming (java), unit 15 kirk scott

36
1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

Upload: nathaniel-reed

Post on 24-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

1

Object-Oriented Programming (Java), Unit 15

Kirk Scott

Page 2: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

2

Simple UML with Visio

• 15.1 Static Structure Diagrams for Classes and Objects

• 15.2 Association, Aggregation, and Composition

• 15.3 Inheritance, Interfaces, and Inner Classes

• 15.4 Sequence Diagrams

Page 3: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

3

15.1 Static Structure Diagrams for Classes and Objects

Page 4: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

4

15.1.1 Classes

• Name, attributes, and operations

Cup Seed

+operations()

-attributes

Cup

+operations()+setSeedCount()+getSeedCount() : int

-seedCount : int = 0

Cup

Page 5: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

5

15.1.2 Objects

• Name, name of class, attribute values

my seed cup : Cup

seeds = 0

my seed cup : Cup

Page 6: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

6

15.1.3 Instances of Classes

-seeds

Cup

seeds = 0

my seed cup : Cup

Page 7: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

7

15.2 Association, Aggregation, and Composition

Page 8: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

8

15.2.1 Binary Associations

• Any kind of relationship• Implemented in any way• Cardinality, navigability, labeling

CupSeedDistributor

1

-adds seeds

0..*

Page 9: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

9

15.2.2 Aggregations

• “has-a” relationship = whole to parts relationship

• May be expressed using a verb more specific than “has”

• Cardinality• May be labeled on both ends

Page 10: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

10

Cup

ArrayList

Seed

1

-has1

1

-has0..*

Page 11: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

11

15.2.3 Compositions

• Like an aggregation, except that the whole cannot exist without the part(s)

Page 12: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

12

Cup

ArrayList

Seed

1

-has1

1

-has0..*

Page 13: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

13

15.3 Inheritance, Interfaces, and Inner Classes

Page 14: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

14

15.3.1 Inheritance

• Subclasses refer to their superclasses

Point2D

Point Point2D.Double Point2D.Float

Page 15: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

15

15.3.2 Interfaces

• “realizes” in European quotation marks may be added as a label.

FoodV5

PackagedFoodV5 BulkFoodV5

TaxedPackagedFoodV5 TaxedBulkFoodV5

«interface»Taxable Interface

Page 16: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

GuillemetsFrom Wikipedia, the free encyclopedia

  (Redirected from Guillemet)

• Guillemets (pronounced /ˈɡɪləmɛt/, or /ɡiːəˈmeɪ/ after French [ɡij(ə)mɛ]), also called angle quotes, are line segments, pointed as if arrows (« or »), sometimes forming a complementary set of punctuation marks used as a form of quotation mark. The symbol at either end – double « and » or single ‹ and › – is a guillemet. They are used in a number of languages to indicate speech. They are also used as symbols for rewind and fast forward.

• Etymology• The word is a diminutive of the French name Guillaume (whose

equivalent in English is William), after the French printer and punchcutter Guillaume le Bé (1525–1598).[1][2] Some languages derive their word for guillemets analogously; for example, the Irish term is Liamóg, from Liam 'William' and a diminutive suffix.

16

Page 17: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

GuillemotFrom Wikipedia, the free encyclopedia

Jump to: navigation, searchFor other uses, see Guillemot (disambiguation).

• Guillemot is the common name for several species of seabird in the order Charadriiformes, and the auk family, comprising two genera: Uria and Cepphus. This word of French origin apparently derives from a form of the name William, cf. the Welsh: Gwillim or the French: Guillaume.[1]

• The Uria are known as murres in North America and, together with the Razorbill, Dovekie and the extinct Great Auk, make up the tribe Alcini. They have distinctly white bellies, thicker, longer bills than Cepphus and form very dense colonies on cliffs during the reproductive season.

• The three species of Cepphus - for which the term "guillemot" is generally reserved in North America - form a tribe of their own: Cepphini. They are smaller than the Uria species, have black bellies, rounder heads and bright red feet.

17

Page 18: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

Merriam-Webster’s Online Dictionary

• Main Entry: guil·le·mot • Pronunciation: \ˈgi-lə-ˌmät\• Function: noun • Etymology: French, from Middle French,

diminutive of Guillaume William• Date: circa 1672• 1 British : a common murre (Uria aalge)

2 : any of a genus (Cepphus) of narrow-billed auks of northern seas

18

Page 19: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

A Common Guillemot Between Two Brunnich’s Guillemots

19

Page 20: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

The Pigeon Guillemot

20

Page 21: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

The Ancient Murrelet

21

Page 22: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

The Marbled Murrelet

22

Page 23: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

23

If the interface is given in full elsewhere this notation can save lines in the

diagram.

TaxedBulkFoodV5

TaxedPackagedFoodV5

Taxable

Taxable

Page 24: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

24

15.3.3 Inner Classes

• This is the official notation.

Page 25: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

25

This is the nearest equivalent I could find in Visio.

Point2D Point2D.Double

Page 26: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

26

15.4 Sequence Diagrams

Page 27: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

27

15.4.1 Sequence Diagrams

• Objects, lifelines, activation rectangles• Message passing = calling methods

and returning• Although not shown in these examples,

messages may be labeled to specify parameters and return values

Page 28: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

28

A call of a method on one object, which triggers a second call:

distributor object

addSeeds()

distribute()

cup object

Page 29: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

29

Calling a method within the same class

distributor object

Page 30: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

30

15.4.2 A Larger Sequence Diagram Example

Let this code be given:

• public abstract class Food• {• private String brand;• private String productName;• private String units;• …• public void setBrand(String brandIn)• {• brand = brandIn;• }• public String getBrand()• {• return brand;• }• …

Page 31: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

31

• public void setBrandToThisBrand(Food anotherFood)• {• String tempBrand = anotherFood.getBrand();• setBrand(tempBrand);• }• …• public abstract double getUnitCost();• }

Page 32: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

32

• public class PackagedFood extends Food• {• private double size;• private double itemCost;• …• public void setSize(double sizeIn)• {• size = sizeIn;• }• public double getSize()• {• return size;• }• …• public double getUnitCost()• {• return itemCost / size;• }• }

Page 33: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

33

Suppose the following is done in a calling program:

• PackagedFood myfood = new PackagedFood(…);

• PackagedFood yourfood = new PackagedFood(…);

• …

Page 34: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

34

Suppose this call is then made:

• myfood.setBrandToThisBrand(yourfood);• The corresponding sequence diagram is shown on the

next overhead.

Page 35: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

35

myfood yourfood

setBrandToThisBrand(yourfood)

getBrand()

tempBrand

setBrand(tempBrand)

Page 36: 1 Object-Oriented Programming (Java), Unit 15 Kirk Scott

36

The End