School of IST

Download Report

Transcript School of IST

School of Information Sciences
and Technology
IST 311 – Object-Oriented Design & Software
Steven Haynes
IST 311 – Class 4
19 January 2006
[email protected]
ist.psu.edu
School of Information Sciences
and Technology
Mid-Term Deliverables
• Use Case diagrams
– Derived from scenarios
• Class diagram
– Conceptual
• Sequence diagrams TBD
– Need use cases first
• User Interface Design
– Need use cases first
• Due Thursday, March 3rd (Thursday before break)
ist.psu.edu
School of Information Sciences
and Technology
Design Representations
• Why learn the UML?
• What is the purpose of design
representation languages and techniques?
ist.psu.edu
School of Information Sciences
and Technology
Design Representations
• An aid to design cognition
• A common language for communicating
about a design (specifications)
• A record of the design process and its
outcomes (documentation)
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams, Part 1.
• Use Case diagram
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Use Case diagram
– Identify major services provided by a system to
external actors (users and other systems)
• Establish the boundaries of the system
• Identify common functionality
• Identify high-level alternate use scenarios
– Capture requirements
– Development project planning tasks
– Communicate with the customer/user.
ist.psu.edu
School of Information Sciences
and Technology
Use Case Diagram
Initialize Pump
«uses»
Purchase Gas
«extends»
Customer
Card Purchase
«extends»
Print Receipt
ist.psu.edu
Bank System
School of Information Sciences
and Technology
Use Cases
•
•
•
•
•
Actors
Use Cases
Include (Uses) Use Cases
Extend Use Cases
Annotations
– Pre-conditions
– Post-conditions
– Constraints
• Don’t use actor or use case generalization
ist.psu.edu
School of Information Sciences
and Technology
Guidelines for Use Cases
• Actors – specific user roles
•
Human actors on left
•
Non-human actors (systems) on right
• Use Cases – verb-noun phrase
•
e.g., Verify Credit Card
• Include (uses) link – included use case MUST be
completed for the including use case to complete
• Extend link – extending use case represents a
variant of the extended use case
ist.psu.edu
School of Information Sciences
and Technology
Guidelines for Use Cases
• Use cases model system interactions.
• Use case granularity THE big problem
• Use annotations (notes) freely to document
your assumptions.
• Use cases are not data stores
• Use cases are not data flow diagrams
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Class diagram
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Class diagram
– Identify classes
• Attributes
• Operations
– Identify class relationships
– Identify packages
– Describe a system’s static structure
ist.psu.edu
School of Information Sciences
and Technology
Class Diagram
Pump_Controller_UI
Transaction
-startButton
-cancelButton
-transTypeButton1
-transTypeButton2
-transTypeButton3
-gradeSelectButton1
-gradeSelectButton2
-gradeSelectButton3
-customerMessage : JTextArea
-unitsDispensed : JTextField
-totalSaleAmount : JTextField
-pricePerUnit : JTextField
-pumpNumberField : JTextField
+Pump_Controller_UI()
+createTransaction()
+monitorCardReader()
+sendAttendantMsg(in message : String)
+initializePump()
+getSelectedFuelProduct()
+promptSwipeCard()
+startDispenser()
+transTypeButton2_actionPerformed()
+setCustomerMsg(in msg : String)
+setFuelProductLabel()
-totalSaleAmount : double
-unitsSold : double
-date : String
+createDispenser()
+calcTotalSale()
+printReceipt()
+Transaction()
*
Card_Transaction
+printReceipt()
+Card_Transaction()
+cardReaderReady() : boolean
1
1
Payment_Card
-cardNumber : String
-nameOnCard : String
-expirationDate : String
-cardVerifiedIndicator : boolean
-amountAvailable : double
+verifyCard() : boolean
+chargeCard()
+Payment_Card()
1
Credit_Card
Debit_Card
-cardCompany : String
-cardBank : String
-pinNumber
+verifyCard() : boolean
+chargeCard()
+verifyCard() : boolean
+chargeCard()
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Sequence diagram
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Sequence diagram
– Describe the sequence of steps required to
realize a use case or use case scenario, which
represent requirements
– Describe interactions between objects/classes
– Perspective is time oriented
ist.psu.edu
School of Information Sciences
and Technology
Sequence Diagram
aPump_Controller_UI
aTransaction
aCustomer
createTransaction()
Pump_Controller_UI()
Transaction()
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Collaboration diagram
ist.psu.edu
School of Information Sciences
and Technology
UML Diagrams
• Collaboration diagram
– Same as Sequence diagram except…
– Perspective is structural or spatial
ist.psu.edu
School of Information Sciences
and Technology
Collaboration Diagram
: PC::Card_Transaction
monitorCard Reader()
ad
Re
d
r
: PC::Card_Reader
a
6: P
d ()
Ca r
nt_
yme
7: verifyCard:=verifyCard()
ca
a
Tr
y:=
_
d
rd
ea
rR
Ca
e
:
d
2
ea
dR
r
ca
4:
5: setCustomerMsg(msg:String)
()
erformed
ist.psu.edu
()
der()
P
2_action
peButton
: PC::Pump_Controller_UI
n
io
ct
a
ns
3: Card_Rea
y
1: transT
Customer
)
y(
ad
e
R
er
: PC::Payment_Card
School of Information Sciences
and Technology
Degree Audit Use Cases & Classes
ist.psu.edu
School of Information Sciences
and Technology
Practice Exploratory Learning!
• Read Raposa chapters with a Java development
environment at hand
• Experiment with his or your own code fragments
to ensure you understand a given point
ist.psu.edu
School of Information Sciences
and Technology
Code Comments, Diagram Annotations
• Always comment your code
• Always annotate diagrams
• Most points are lost on assignments and
projects because of clarity issues.
Comments and annotations help overcome
these problems.
ist.psu.edu
School of Information Sciences
and Technology
Important from Chapters 1-3
• Ch. 1
–
–
–
–
–
–
The JVM
Bytecodes
Classes vs. Objects
.java vs. .class files
Command-line arguments
The main method
• Ch. 2
–
–
–
–
Java keywords
Java identifiers
Primitive data types
Declaring, initializing,
assigning variables
ist.psu.edu
–
–
–
–
–
Java Strings
Reference vs. primitive data
Constants
Operators
Comments
• Ch. 3
– Java control structures
– Boolean operators and logic
School of Information Sciences
and Technology
Assumptions
• You know what data types are and can select the
appropriate type from those available in Java
• You know what Java keywords are and can find
and use them appropriately
• You can declare, initialize, and use Java variables
and constants
ist.psu.edu
School of Information Sciences
and Technology
Assumptions Continued
• You know what operators are and can use them
– Logical: AND (&&), OR (||), EXCLUSIVE-OR (^)
and NOT (!)
– Arithmetic: Addition (+), Subtraction (-), Multiplication
(*), Division (/), Modulus (%)
– Increment (e.g., i++, ++i), Decrement (e.g., k--, --k)
– Assignment (=, +=, -=, *=, /=, %=)
– Relational (==, <, >, <=, >=, !=)
• You know how to use the different Java comment
types
ist.psu.edu
School of Information Sciences
and Technology
Classes and Objects
• What’s the difference?
ist.psu.edu
School of Information Sciences
and Technology
Classes and Objects
• A class is a blueprint or template for
creating objects and defines
– An object’s attributes
– An object’s behaviors (methods)
• An object is an instance of a class
• To create objects we instantiate a class
ist.psu.edu
School of Information Sciences
and Technology
Java Strings
• A string is a collection of character (char) data. Strings are
important data structures in any programming language
• A java.lang.String object is a sequence of characters plus a
collection of methods for manipulating strings.
• Unlike other Java objects, Strings have certain
characteristics in common with the primitive data types.
• For example, strings can have literals. A String literal is a
sequence of zero or more characters contained in double
quotes -- for example, “Socrates” and “” (empty string).
ist.psu.edu
School of Information Sciences
and Technology
Java Strings
• The + symbol is used as a binary concatenation operator
for Strings. It has the effect of joining two strings together.
• Primitive types are automatically promoted to strings when
mixed with concatenation operators.
• The number of characters in a string is its length.
• The position of a character within a string is called its
index. Strings are zero indexed -- the first character is at
index 0.
• The String.valueOf() methods are class methods that
convert primitive types into String objects.
• The indexOf() method searches from left to right within a
String for either a character or a substring.
ist.psu.edu
School of Information Sciences
and Technology
Java Strings
• Methods for comparing strings:
public boolean equals(Object anObject); // Overrides
Object.equals()
public boolean equalsIgnoreCase(String anotherString)
public int compareTo(String anotherString)
• Two strings are equal if they have the same letters in the same order:
String s1 = "hello";
String s2 = "Hello";
s1.equals(s2)
// false
s1.equals("hello”); // true
• Error: Using = = to compare two strings. For objects, o1 = = o2
means o1 and o2 are identical.
ist.psu.edu
School of Information Sciences
and Technology
Java Strings
• Java Strings cannot be modified. Whenever you assign a
new value to a String, Java must create a new String object
and discard the old one.
• Objects of java.lang.StringBuffer class are strings that can
be modified.
ist.psu.edu
School of Information Sciences
and Technology
Java Strings
• A StringTokenizer breaks a string into tokens separated by
delimiters, which by default value are the whitespace
characters:
StringTokenizer sTokenizer
= new StringTokenizer("This is an English
sentence.");
This
is
an
English
sentence.
ist.psu.edu
School of Information Sciences
and Technology
Control Structures
– Sequence --- The statements in a program are executed
in sequential order unless their flow is interrupted by
one of the following control structures.
– Invoke or Call a Method --- Invoking a method
transfers control temporarily to a named method.
Control returns to the point of invocation when the
method is completed.
– Decision/Selection--- The if, if/else, and switch
statements are branching statements that allow choice
by forking of the control path into two or more
alternatives.
– Repetition --- The for, while, and do-while statements
are looping statements that allow the program to repeat
a sequence of statements.
ist.psu.edu
School of Information Sciences
and Technology
Control Structures
• No matter how
large or small a
program is, its
flow of control
can be built as a
combination of
these four
structures.
• Note that each
structure has one
entry and one
exit.
ist.psu.edu
School of Information Sciences
and Technology
Repetition
• Repetition structure: a control structure that
repeats a statement or a sequence of statements.
• A counting loop can be used if you know in
advance how many iterations are needed. The for
statement is used for counting loops.
• A while structure should be used if the loop body
may be skipped entirely. The while statement is
used.
• A do-while structure should be used only if a loop
requires one or more iterations. The do-whilestatement should be used.
ist.psu.edu
School of Information Sciences
and Technology
Loop Elements
• The loop variable, which is used to specify the
loop entry condition, must be initialized to an
appropriate value and updated on each iteration.
• A loop's bound, which may be a count, a sentinel,
or, more generally, a conditional bound, must be
correctly specified in the loop-entry expression,
and progress toward it must be made in the
updater.
• An infinite loop may result if either the initializer,
loop-entry expression, or updater expression is not
correctly specified.
ist.psu.edu
School of Information Sciences
and Technology
Homework Assignment
• This is an individual assignment.
• Read Raposa Chapter 4.
• Using Eclipse, write a Java class for each of the
classes you designed for homework #2.
• Write another class (a program), the main class
with the main() method, that creates an instance of
each of these classes, then calls one method in
each to output the method name.
• Due at the start of class Tuesday, 1/24.
• Hand in hard copies of the object definitions
(classes) and of the source code.
ist.psu.edu