Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
1Introduction
Course Overview
1
Lecture 1
Agenda
„ Administrativa
C bj ti d tli„ ourse o ec ve an  ou ne
„ Course Glossary
„ OOAD
„ UML
„ Methodology: Iterative Development
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
2
„ Pattern
2Administrative
„ Instructor
„ Dr. Bernhard Scholz (scholz@it.usyd.edu.au)
„ Office: SIT 411
„ Lectures
„ Time: Monday 6-8 pm
„ First Week: Farrell Theatre
„ Labs
„ Monday, 8-9 pm, SIT Labs 115-117, Madsen LG31  
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
3
„ start from week 2
„ Course Website:
„ http://www.cs.usyd.edu.au/~comp5028/
Communication Channels
„ Consultation
T d 2 3 SIT 411„ ues ay - pm,  
„ Email: scholz@it.usyd.edu.au
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
4
3Objectives
„ Learn O-O A&D methodology
L UML (U ifi d M d li L )„ earn n e  o e ng anguage
„ Learn O-O design patterns/principles
„ Build something that illustrates the concepts
And the ultimate goal is…
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
5
To write good software
Enrolment advise
„ Who should take this course?
„ Do you know Java/C#?   
„ Do you have enthusiasm in software 
development? 
„ Can you appreciate beautiful structure? 
„ Who should probably back away from this 
course?
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
6
„ Are you completely new to Java/C#?
„ Are you looking for a course to get easy mark?
„ Do you hate coding?
4Expectations
„ Assumed Knowledge
„ Java or other similar OO language (C#)      
„ Java is the official language in this course
„ BEFORE each lecture
„ Download and printout the lecture slides 
„ Read the related chapter(s) and lectures notes
„ Read the tutorial instruction
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
7
   
„ Make sure you keep up with the progress
„ Consult course staff EARLY enough for 
difficulties and problems!
Course Outline
„ Two Major parts of the content
I t t OOP (1 k)„ n ro o   wee
„ OOA (5 weeks)
„ Use Case Model, Domain Modeling
„ OOD (5 weeks)
„ Design principles and patterns
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
8
5Assessment Components
„ One hour quiz (open book) (20%)
„ Held in week 6’s tutorial hour
„ Result back in week 8
„ Assignment (20%)
„ Due in week 12 
„ But sub-tasks are due over the semester
„ Results will be published on WebCT two weeks after the due 
date, please check WebCT to make sure that your results are 
correctly recorded. Any discrepancies should be resolved 
ithi k ft th lt b i bli h d!
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
9
w n one wee  a er e resu  e ng pu s e
„ Final Exam (60%)
„ closed book, 2 hours
„ sample exam will be given
„ should expect question regarding coding
Our Textbook
„ Craig Larman, Applying UML 
and Patterns: An Introduction 
to Object Oriented Analysis -   
and Design and Iterative 
Development, 3rd edition, 
Prentice Hall PTR, 2005
„ Detailed Intro to Object-
Oriented Analysis & Design
„ Unified Modeling 
Language (UML)
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
10
„ Design Patterns
6Reference Books
„ Martin Fowler, UML Distilled, 3rd edition, Addison-
Wesley, 2004 
„ Robert C. Martin, Agile Software Development: 
Principles, Patterns and Practices, Prentice Hall, 
2003 
„ Erich Gamma, Richard Helm, Ralph Johnson, John 
Vlissides, Design Patterns, Addison-Wesley, 1995 
„ Allan Shalloway ,James R. Trott Design patterns 
explained: A new perspective on Object-Oriented 
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
11
Design, 2nd edition, Addison-Wesley, 2005.
„ Eric Freeman, Elisabeth Freeman, Kathy Sierra and 
Bert Bates, Head First Design Patterns, O'Reilly, 
2004 
Software
„ Microsoft Visio 
Li d ft„ cense  so ware
„ Installed on the lab PCs
„ Used for drawing diagrams
„ J2SE 1.5 or above
„ Free download from java.sun.com
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
12
„ Used for running sample code or assignment
7Rule of Conduct
„ Okay to discuss ideas and problem approaches
„ All work must be your own creation      
„ Plagiarism will not be tolerated under any circumstance!
„ Plagiarism form needs to be signed for assignment and 
handed in. 
„ What is plagiarism
„ Copying all or part of another student’s work (with or 
without their knowledge)
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
13
„ Using another person’s ideas without 
acknowledgement
„ Obtaining material (code or other) from the web or a 
book and handing it in as your own 
Questions?
14
8What is good software?
„ End Users:
M„ anagers:
„ Developers:
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
15
Today’s lecture topic
„ Programming Languages: Influence on A&D
Wh t i OOAD?„ a  s 
„ Basic OOAD methodology: Iterative 
Development
„ What is UML?
„ What is PATTERN
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
16
9A brief history of 
Programming Languages
„ Early Days
„ electronic Numerical Integrator And Computer     
(ENIAC), ~1940
„ cards for Input/Output
„ programming: 
„ by rewiring cables
„ was not efficient 
*
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
17
* Picture taken from wikipedia
Next bigger step
„ Introduction of Assembler Language (~1950)
„ improved programmer’s productivity
„ isomorphic translation to machine code
„ Example
„ Intel IA32 (x86)
„ compute greatest 
common divisor
gcd:    pushl   %esi
pushl   %ebx
pushl   %ecx
movl    20(%esp), %edx
testl   %edx, %edx
movl    16(%esp), %ecx
je      .L7
.L5:    movl    %ecx, %eax
movl %edx %ebxfunction gcd(a b):
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
18
    , 
cltd
idivl   %ebx
testl   %edx, %edx
movl    %ebx, %ecx
jne     .L5
.L7:    popl    %edx
popl    %ebx
movl    %ecx, %eax
popl    %esi
ret
, 
if b = 0 return a
else return gcd(b, a mod b)
10
A big step...
„ Introduction of high-level languages (~1960-now) 
„ examples: FORTRAN LISP Pascal C etc , , , , .
„ clear defined syntax/semantics
„ platform independent
„ describing data and data structures 
(array, lists, etc.)
„ well-formed structure for control flow (functions/ 
procedures if switch/case loops etc )
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
19
, , , , .
„ Improved productivity by a factor of 10
„ but still not enough  
Current State & Future
„ Current state: object oriented languages (~1970-now)
„ Examples: Simula, Smalltalk, (later Java and C#)
„ Encapsulate data and control in objects
„ Classes and types ease modeling of complex systems
„ Clear benefit for implementing large-scale systems
„ Future: 
„ dynamic scripting languages
„ component languages 
„ functional programming languages
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
20
  
„ parallel languages (execution platform will change soon)
„ New languages & paradigms will have an impact 
how we analyze and design software and vice 
versa!
11
What is Analysis and Design
„ Analysis emphasizes an investigation of the 
problem rather than how a solution is defined       
„ Design emphasizes a logical solution, how 
the system fulfills the requirements
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
21
Analysis and Design (cont)
„ Division between A & D is fuzzy
„ A & D activities exist on a continuum       
„ Some practitioners can classify an activity as 
analysis while others put it into design category
More analysis oriented More design oriented
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
22
-what
-requirements
-investigation of domain
-understanding of problem
-how
-logical solution
-understanding and  
description of solution
12
What is O-O A&D?
„ The essence of O-O A&D is to consider a 
problem domain and logical solution from the       
perspective of objects (things, concepts, or 
entities)
„ O-O Analysis emphasizes finding and 
describing the objects – or concepts- in the 
problem domain
O O D i h i d fi i l i l
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
23
„ -  es gn emp as zes e n ng og ca  
software objects (things, concepts, or entities) 
that have attributes and methods
Object vs. Function Oriented Analysis
Library Info 
System
O-O A&D
Decompose by objects and concepts
Structured A&D
Decompose by functions and processes
Catalog Librarian
System
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
24
Book Library Record Loans Add Resource Report Fines
13
Object vs. Function Oriented Analysis
„ Object has good 
encapsulation
„ Every object has a 
public interface and 
private implementation
„ Easy to modify the 
detailed 
implementation
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
25
„ Easy to plug in / switch 
component
Unified Modeling Language
„ “A language for specifying, visualizing and 
constructing the artifacts of software system”      
[Booch, Jacobson, Rumbaugh]
„ It is a notational system aimed at modeling 
systems using O-O concepts
„ Define " boxes", "lines " with specific 
meanings
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
26
14
UML diagrams
„ Use case diagram
„ Class diagram
„ Behavior diagrams:
„ statechart diagram
„ activity diagram
„ interaction diagrams:
„ Sequence diagram
„ Collaboration diagram
„ Implementation diagrams:
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
27
 
„ component diagram
„ deployment diagram
What is legal UML?
„ Legal UML is what is defined as well formed in the 
specification
„ Prescriptive rules
„ A language with prescriptive rules is controlled by an 
official body that states what is or isn’t legal in the 
language and what meaning you give to utterances in 
that language
„ Descriptive rules
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
28
„ A language with descriptive rules is one which you 
understand its rules by looking at how people use the 
language in practice
15
OOA/D Methodology
„ What does methodology mean?
B i t„ as c s eps
„ An overall plan of organizing those steps
„ Rationale and philosophy
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
29
Key Steps in OOAD [1]
Define domain Define interaction Define designDefine use cases
Use Case: a textual description or “story” describing the system
Example:
model diagrams class diagrams  
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
30
Play A Dice Game: “A player picks up and rolls the dice.
If the dice face values total seven, they win; otherwise, they lose.”
16
Key steps in OOAD [2]
Define domain Define interaction Define designDefine use cases
Domain Model: diagram(s) showing domain concepts, attributes,
and associations
Example: Player
name
Die
faceValue
Rolls 2
2
1
1
model diagrams class diagrams
  
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
31
DiceGame
Plays
Includes
1
1
Key steps in OOAD [3]
Define domain Define interaction Define designDefine use cases
Interaction Diagram: shows the flow of messages between software
objects (method invocation)
:DiceGame
play()
die1 : Die die2 : Die
roll()
Example:
model diagrams class diagrams  
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
32
fv1 := getFaceValue()
roll()
fv2 := getFaceValue()
17
Key steps in OOAD [4]
Define domain Define interaction Define designDefine use cases
Class Model: shows attributes, methods and associations
for software (solution) objects (not domain objects!)
2
DieDiceGame
1
Example:
model diagrams class diagrams  
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
33
faceValue : int
getFaceValue() : int
roll()
die1 : Die
die2 : Die
play()
Iterative and Evolutionary 
Development
„ Iterative development
D l t i i d i t i f„ eve opmen  s organ ze  n o a ser es o  
short, fixed-length mini-projects called 
iterations.
„ The outcome of each is a tested, integrated, 
and executable partial system. 
„ Known as iterative and incremental
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
34
     
development
18
Iterative and evolutionary 
development
Requirements Requirements Feedback from
iteration N leads to
Design
Implementation &
Test & Integration
& More Design
Final Integration
& System Test
Design
   
refinement and
adaptation of the
requirements and
design in iteration
N+1.
Time
Implementation &
Test & Integration
& More Design
Final Integration
& System Test
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
35
4 weeks (for example)
The system grows
incrementally.
Iterations are fixed in
length, or timeboxed.
Handle change on iterative project
Early iterations are farther from the "true
In late iterations a significant change inpath" of the system. Via feedback and
adaptation, the system converges towards
the most appropriate requirements and
design.
  ,    
requirements is rare, but can occur. Such
late changes may give an organization a
competitive business advantage.
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
36
one iteration of design,
implement, integrate, and test
19
How long should an iteration be?
„ Most iterative methods recommend an 
iteration length between two and six weeks      .
„ Iteration are timeboxed, or fixed in length
„ Date slippage is illegal
„ If it seems difficult to meet the deadline, the 
recommended response is to de-scope –
remove tasks or requirements from the 
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
37
iteration, and include them in a future iteration
The oldest waterfall lifecycle
„ Attempt to define all or most of the requirements 
before programming. To create a thorough design       
before programming
„ Strongly associated with high rates of failure, lower 
productivity, and higher defect rates.
„ 45% of the features in waterfall requirements are 
never used, early waterfall schedules and estimates 
vary up to 400% from the final actuals
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
38
       .
20
Mini workshop
„ Which one of the following is true iterative 
development
„ I’ve done five iterations on requirement collection and 
the client finally satisfied and signed off the 
requirement document.
„ We take iterative method to achieve good database 
design. After the first interview with the client, we make 
an initial design of the database and brought this to the 
client. We got valuable feedback from them and made 
according changes, we repeat this process for four 
times and now have our final version of the database
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
39
          
design
How to do iterative and evolutionary 
analysis and design
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
40
21
Unified Process (UP) -- Methodology
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
41
UP Phases
„ Inception – Approximate vision, business case, 
scope, vague estimates  
„ Elaboration – refined vision, iterative implementation 
of the core architecture, resolution of high risks, 
identification of most requirements and scope, more 
realistic estimates
„ Construction – iterative implementation of the 
remaining lower risk and easier elements and
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
42
     ,  
preparation for deployment
„ Transition – beta tests, deployment
22
Patterns
„ Solution path to recurring problems in 
software development project  
„ Design patterns
„ Analysis patterns
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
43
An overall picture
„ A development task
A bl i t f t t hi th t k„  ue pr n  o  s eps o ac eve e as  
(methodology, example: UP)
„ A few tricks or shortcuts in each step 
(principles and patterns)
„ An efficient way to communicate the job/result 
f h t (UML di )
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
44
o  eac  s ep  agram
23
Layers and texbook case study
User Interface
Sale Paymentapplication 
logic layer
minor focus
explore how to connect to 
other layers
primary focus 
of case studies
explore how to 
design objects
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
45
Logging ... Database Access ...
other layers or 
components
 
secondary 
focus
Thanks…
„ But let’s have a small java test ….
COMP5028 Object-Oriented Analysis and Design 
© Y. Zhou, and B. Scholz, School of IT, The University of Sydney 
46