Title: Modular Programming and UML Class and Object Diagrams
1Modular Programming andUML Class and Object
Diagrams
- Session 4
- LBSC 790 / INFM 718B
- Building the Human-Computer Interface
2Agenda
- Modular Programming
- Homework Java
- UML Class and Object Diagrams
- Homework Use Cases
- Idea Rally
3Sources of Complexity
- Java syntax
- Learn to read past syntax to see ideas
- Copy working examples
- Interaction of data and control structures
- Structured programming
- Object structure
- Practice modeling using UML
- Modularity
- Our focus this week
4Modularity? Who cares?
- Limit complexity
- Extent
- Interaction
- Abstraction
- Minimize duplication
5What can go wrong here?
Input
Output
6Defensive Programming
- Goal of software create desired output
- Programs transform input into output
- Some inputs may yield undesired output
- Methods should enforce input assumptions
- Guards against the user and the programmer!
- Everything should be done inside methods
7Passing Arguments in Java
- Call by value
- Primitive data types
- Object references
- The two meanings of equal
- Overloaded method names
- Depends on parameter type, number, and order
8Returning Values in Java
- Return type declaration
- No return statement for void
- Return statement causes termination
- Multiple return statements can be present
- First one executed causes termination
- Type must match declaration
- Objects encapsulate complex return types
9Uses of Methods in Java
- Constructor
- Set and get
- Helper
- Event handler
- Stay tuned until we get to GUIs
10Classes to Explore in the API
- String
- Manipulate strings (e.g., to extract substrings)
- StringTokenizer
- Pick apart strings (e.g., into words)
- GregorianCalendar
- Dates and times
- Hashtable
- Like arrays, but with any object as the index
11Exercise
- Read the Book class
- Create the Library class
- Test the two together
12Things To Pay Attention To
- Syntax
- How layout helps reading
- How variables are named
- How strings are used
- How output is created
- How applications are invoked
- Structured Programming
- How arrays are used
- How boolean flags are used
- Modular Programming
- Modularity of methods
- How methods are invoked
- How arguments work
- How scope is managed
- How errors are handled
- How results are passed
- Object Structure
- How classes are defined
13(No Transcript)
14Getting to the Object Structure
- Capturing the big picture
- Designing the object structure
- Class diagram (entity-relationship diagram)
- Object diagram (used to show examples)
- Represent a candidate workflow
- Represent object interactions for a scenario
- Represent event-object interactions
15Object Modeling
- Models are abstractions of reality
- That are created for a specific purpose
- Classes represent types of entities
- That are important for the chosen purpose
- Specify subordinate objects and methods
- Objects are specific instances of classes
- Encapsulate specific objects and methods
16Bills Budget Flight Finder
17Flight Finder Background
- The traveler may specify the origin, destination,
type of flight (e.g. one-way, round-trip) exact
or approximate dates, and then initiate the
search. Once the search completes, the traveler
may step through the interesting routes one at a
time, viewing information on which their decision
might be based. Once one or more acceptable
routes have been identified, the traveler can
then select and book the flight, by providing
personal and payment information.
18FlightFinder Use Case Diagram
Search
ltltincludegtgt
AA/ Sabre
Process Sched
Select
ltltincludegtgt
Traveler
ltltincludegtgt
Book
19Search Use Case Narrative
- Assumptions
- Current AA/Sabre schedule available
- Pre-conditions
- None
- Initiation
- Search function selected
- Dialog
- Search parameters selected, search initiated,
unknown locations resolved, route list displayed - Termination
- Route search complete (normal), unknown location
(error) - Post-conditions
- Route list displayed (if available) or blank
20Select Use Case Narrative
- Assumptions
- Route list displayed
- Pre-conditions
- At least one available route
- Initiation
- Route selected from list
- Dialog
- Select route, display details in
maptimelinetext - Termination
- Display completed
- Post-conditions
- Details displayed
21Flight Finder Background
- The traveler may specify the origin, destination,
type of flight (e.g. one-way, round-trip) exact
or approximate dates, and then initiate the
search. Once the search completes, the traveler
may step through the interesting routes one at a
time, viewing information on which their decision
might be based. Once one or more acceptable
routes have been identified, the traveler can
then select and book the flight, by providing
personal and payment information.
22Bills Budget Flight Finder
23FlightFinder Class Diagram (1)
1..9
1
1..
Route
Leg
Flight
Sequence of
Sequence of
Flies between
Contains
Displayed in
1
2
0..1
1
GUI
Airfield
Schedule
1
1
Travel between
Uses
Displayed in
1
1
2
Map
Location
AircraftType
Displayed in
1
Timeline
24Relationships
- Object relationships
- Has-a
- Aggregation
- Composition
- Class relationships
- Generalization (extends)
- Implements
25FlightFinder Class Diagram (2)
1..9
1
1..
Route
Leg
Flight
Sequence of
Sequence of
addLeg(lLeg) summary()String
-seats integer -departureTime
Time -arrivalTimeTime parse(sString) summary()
String
-flightNumberString parse(sString)
Displayed in
Flies between
Contains
0..1
Uses
GUI
Airfield
Schedule
1
1
search(pParam) display(rRoute)
-nameString -icaoIdentifierString4
-updatedTime -sourceURL parse(fFile)
2
1
1
Travel between
1
Map
Location
AircraftType
Displayed in
2
Displayed in
draw(rRoute)
-latitudedouble -longitudedouble -timeZoneTimeZ
one distanceTo(lLocation)
-nameString -speedint flightTime(oLocation,
dLocation)
1
1
Timeline
draw(rRoute)
26FlightFinder Object Diagram
1st
1Route
2nd
NV514Flight
Leg
-flightNumberNV514
-seats34 -departureTime1600Z -arrivalTime1900Z
Leg
AF302Flight
LambertAirfield
GUI
-seats3 -departureTime1200Z -arrivalTime1400Z
-flightNumberAF302
-nameLambert Field -icaoIdentifierKSTL
O
AndrewsAirfield
LAXAirfield
Sep26Schedule
-nameAndrews AFB -icaoIdentifierKADW
-nameLA Intl Airport -icaoIdentifierKBLV
D
Map
-updatedSep 26/1200Z -sourcehttp//www
O
DCLocation
ScottAirfield
D
-latitude38-48N -longitude076-51W -timeZoneEAST
ERN
-nameScott AFB -icaoIdentifierKBLV
O
C-9BAircraftType
Timeline
-nameC-9B -speed450 knots
LALocation
Key O Origin D Destination
-latitude33-57N -longitude118-24W -timeZonePACI
FIC
D
27Class Critique
- Multiple instances must be possible
- Each uniquely identifiable
- Cant be subdivided into distinct classes
- Multiple attributes needed to describe
- No empty attribute values
- Methods needed
- At least for creation and modification
28Attribute Critique
- Naturally describes the object
- Does not describe some other object
- Value will be known for some instances
- Value will never be empty
- Cannot be subdivided into smaller attributes
- One value, not a list of values
- Cannot be computed from other attributes
29Practice Exercise
- Create a Class Diagram for an academic transcript
- Include a method to compute grade point average
- Include a method to print the transcript
- Code (only) the transcript class in java
- Include a main method that tests the class
- Create stubs for any other needed classes
- Run your main method
30(No Transcript)
31Idea Rally
- Pitches rigidly timed (90 seconds)
- Focus on the points that you believe will most
impress your classmates - Not graded
- Discussion afterwards
32Show 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?
33Coming up
- Exercise 3 (self-graded)
- Will post by Friday evening
- Not Graded
- Next week
- Object-oriented programming
- Read HFJ 7,8, and 9
- Collaboration and sequence diagrams
- Read UML, sessions 16-19
34Muddiest Point(s)
- The most confusing thing discussed
- Modular programming Java
- UML
- One sentence each