21
Object-oriented Programming and Collaboration and Sequence Diagrams Session 5 LBSC 790 / INFM 718B Building the Human-Computer Interface

Object-oriented Programming and Collaboration and Sequence Diagrams Session 5 LBSC 790 / INFM 718B Building the Human-Computer Interface

Embed Size (px)

Citation preview

Object-oriented Programming and

Collaboration and Sequence Diagrams

Session 5LBSC 790 / INFM 718B

Building the Human-Computer Interface

Agenda

• Object-Oriented Programming– Exercise questions– Working with the Java API

• Javadoc documentation• Packages

– Subclasses & object creation (maybe)

• Collaboration and Sequence Diagrams

• Idea Rally, part 2

Classes to Explore in the API

• String– Manipulate strings (e.g., to extract

substrings)

• NumberFormatter– So you can print pretty numbers

• Math– Useful math functions

• GregorianCalendar– Dates and times

Working with the Java API

• Instantiate an object:– String s = new String(“test”);– int i = s.indexOf(“s”);

• Directly use a static method:– int z = Math.min(x,42);

• Use a static method to get an object:– NumberFormatter f =

NumberFormat.getCurrencyInstance();– String d = f.format(327);

Java Classes

• Java classes represent types of things– Can be thought of as blueprints for objects

• Classes = state + actions– State is represented by variables– Actions are represented by methods

• Scope rules support abstract thinking– Public: can be used from other classes– Private: can only be seen in the class

Subclasses & Inheritance

Location

Airfield-airportCode:String{3}+getAirportCode()+getDistanceTo(a:Airfield)

-latitude:double-longitude:double-timeZone:TimeZone-name:String+distanceTo(l:Location)+getName()

(is-a)

Object creation

• The stack– Local variables

• The heap– Instance variables

• Constructors

Exercise 3, part 4Library

+search(...)

Book

-title:String-author:Str’g-copyrightYear:integer-available:integer

+checkIn()+checkOut()+equals(b:Book)

Size

-width:double-height:double

+equals(s:Size)

3..30..*

owns1*

has

Bill’s Budget Flight Finder

Fli

es b

etw

een

*

0..11

1

FlightFinder Class Diagram (2)

Route

GUI

Map

Timeline

Location

Airfield

Leg

AircraftType

Schedule

Flight

1

*

1..9 11..**

Sequence ofSequence of

2

1

Travelbetween

+addLeg(l:Leg)+summary():String

+search(p:Param)+display(r:Route)

+draw(r:Route)

+draw(r:Route)

-seats: integer-departureTime: Time-arrivalTime:Time+parse(s:String)+summary():String

-name:String-icaoIdentifier:String{4}

-latitude:double-longitude:double-timeZone:TimeZone+distanceTo(l:Location)

-flightNumber:String

+parse(s:String)

-updated:Time-source:URL

+parse(f:File)

-name:String-speed:int

+flightTime(o:Location, d:Location)

Con

tain

s

Use

s

Dis

play

ed in

Dis

play

ed in

1

1

Displayedin

1

*

2

*

D

FlightFinder Object Diagram

1:Route

:GUI

:Map

:Timeline

DC:Location

Andrews:Airfield

:Leg

C-9B:AircraftType

Sep26:Schedule

AF302:Flight

-seats=3-departureTime=1200Z-arrivalTime:1400Z

-name=Andrews AFB-icaoIdentifier=KADW

-latitude:38-48N-longitude:076-51W-timeZone=EASTERN

-flightNumber:AF302

-updated:Sep 26/1200Z-source:http://www…

-name=C-9B-speed=450 knots

LA:Location

-latitude=33-57N-longitude=118-24W-timeZone=PACIFIC

Scott:Airfield

-name=Scott AFB-icaoIdentifier=KBLV

Lambert:Airfield

:Leg

-seats=34-departureTime=1600Z-arrivalTime=1900Z

-name=Lambert Field-icaoIdentifier=KSTL

LAX:Airfield

-name=LA Intl Airport-icaoIdentifier=KBLV

NV514:Flight

-flightNumber:NV514

O

D

O

O

D

1st

2nd

Key: O = Origin D = Destination

Modeling the system

• Capturing the big picture

• Designing the object structure– Class diagram (“entity-relationship” diagram)– Object diagram (used to show examples)

• Represent object interactions for a scenario

• Represent event-object interactions

Collaboration Diagram1:Route

:GUI

:Map

:Timeline

DC:Location

Andrews:Airfield

second:Leg

C-9B:AircraftType

Sep26:Schedule

AF302:Flight

LA:Location

Scott:Airfield

Lambert:Airfield

first:Leg

LAX:Airfield

NV514:Flight

1:ge

tTex

t() 7:getText()

2:getText()

5:ge

tTex

t()

6:ge

tTex

t()

3:getText()

4:ge

tTex

t()

10:g

etT

ext(

)

11:g

etT

ext(

)

8:getText()

9:ge

tTex

t()

13:g

etL

atL

ong(

)

12:g

etL

atL

ong(

)

15:p

lot(

r:R

oute

)

14:p

lot(

r:R

oute

)

Scenario: First route selected

Sequence Diagram

:GUIall:Airfieldsnear:Airfields andrews:Airfield first:Leg

findNear(dept):Airfields

return near

nextAirfield():Airfield

return andrews

nextLeg():Leg

return first

getDestination():Airfield

return scott

return near

findNear(scott):Airfields

Continue depth-first search, pruning unsuccessful routes after 9 legs

Idea Rally – part 2

• Pitches rigidly timed (90 seconds)• Focus on the points that you

believe will most impress your classmates

• Discussion afterwards– Exchange / refine ideas– Start forming teams

Coming up

• Homework 2– Will post by Friday evening– Graded

• During the coming week– Form teams; email 2 sentence description

to me– Use the lab

• Next week:– More on object-oriented programming

• Read: HFJ 10 & 11

– Maybe preview: Graphical user interfaces– Project check-in

Stop / Start / Continue

• Please write one thing that you would like us to…– Stop doing *– Start doing– Continue doing

…in class

* Note: homework will not stop…

Show and Tell

• What cool resources have you found?– Books and Web sites?

• What new Java tricks have you learned?

• What do you need to know to make progress?