A simple software developement process from specification

Download Report

Transcript A simple software developement process from specification

Java case studies: game playing
A simple software development process
from specification, to design,
implementation, and test
DAAD project
“Joint Course on OOP using Java”
Humboldt University Berlin, University of Novi Sad, ‘Polytehnica’ University of Timisoara,
University of Plovdiv, University of Belgrade
Author: Dušan Tošić
Version: Sep. 2, 2005
Points of this development Java For
the lecturer
only
sample game
Create a simple game
by using Java
Illustrate a
methodology how
to develop a Javaapplet step by
step.
Using Java API
DAAD project „Joint Course on OOP using Java“ ©
Demonstrate the
importance of
software
engineering
principles for simple
Java programs
development
Inspired by the
lecture K. Bothe
“Mouse in a Maze”
2
Course materials
For
the lecturer
only
 Lecture slides:
• about 20 slides
• takes 2 lecture hours (to complete the whole process)
 Assignments:
• modify presented program
• make new games using presented example.
DAAD project „Joint Course on OOP using Java“ ©
3
Global description of the task:
“Lost cat”
Task:
Develop a program, to simulate the finding
of a lost cat by using information ‘closerfurther’.
First step?
DAAD project „Joint Course on OOP using Java“ ©
Next steps?
4
Facts concerning software
development phases
This slide is
taken from K.
Bothe
Most errors of software systems result from
misunderstanding the problem to be solved.
Software development consists only of a
small part of programming:
•
•
•
•
Requirements analysis: 20 %
Design:
15 %
Implementation: 20 %
Test: 45 %
DAAD project „Joint Course on OOP using Java“ ©
5
Learning goals
This example should illustrate the
importance of a complete and correct
requirements specification for the project
success.
Before implementing, try to apply all
previous phases in SW development.
Start with the implementation when all
classes and methods are known.
DAAD project „Joint Course on OOP using Java“ ©
6
Development process of
‚Lost cat‘
Requirements analysis
Design
Implementation and test
DAAD project „Joint Course on OOP using Java“ ©
7
Requirements analysis:
‚Lost cat‘
Task:
Develop an applet (using GUI), to simulate
the searching a lost cat. The position of cat
is randomly chosen. The searching is
simulated by mouse-clicks.
Open questions ?
DAAD project „Joint Course on OOP using Java“ ©
8
Open questions
How to mark a visited position?
How to keep the visited positions?
How to present information „you are closer
(further) to the cat“?
When the cat is found?
What will happen when the cat is found?
What is the environment where we look
for?
DAAD project „Joint Course on OOP using Java“ ©
9
Requirements specification (1,2)
We point out the position of a lost cat by
mouse-click in current position of the mouse
pointer. We will mark the chosen position in
some way. The different kinds of flags, can be
used, but we decide to use the simplest one:
the filled circle.
visited position
We will keep the visited positions in an array.
(Data structures like: vectors, linked lists, … could
be used too.) By using this array we will draw the
circles.
DAAD project „Joint Course on OOP using Java“ ©
10
Requirements Specification (3)
We will use two ways to inform the player
about position of the cat:
by text-messages
by flags (circles)
The different colors of flags determine whether
the chosen position is closer or further (related
to previous position) from the cat.
The following colors are used:
start position
closer
further
found cat
DAAD project „Joint Course on OOP using Java“ ©
11
Requirements Specification (4,5)
If the point (xc, yc) is
position of the cat
and (x,y) position of
the mouse pointer, we
will suppose that the
cat is found if:
(|xc-x|<10) &
(|yc-y|<10)
(We may measure the
distance on some
other way.)
When the cat is found,
the picture of the cat
will fill the window of
applet. The follow
picture is used:
DAAD project „Joint Course on OOP using Java“ ©
12
Requirements Specification (6)
We can use any color
for the background of
our applet. Moreover,
it is more convenient
to simulate nature
environment in some
way. We deside to use
the following picture to
simulate the nature
environment
DAAD project „Joint Course on OOP using Java“ ©
13
Development process of
‚Lost cat‘
Requirements analysis
Design
Implementation and test
DAAD project „Joint Course on OOP using Java“ ©
14
Design: develop the software architecture
SW architecture description languages:
UML- industry standard.
Main problem: How to find classes?
„Finding a proper class structure may be
more challenging then implementing the
Java program code“ (K. Bothe).
DAAD project „Joint Course on OOP using Java“ ©
15
Software architecture
Our task is not so complicated (it is a simple
student’s assignment!) Thus, the structure of
our program should not be complicated.
Moreover, we have to define:
Which components exist?
Which relations are between them?
We will have a main class (CatGame) and an
auxiliary class (Mouse)
DAAD project „Joint Course on OOP using Java“ ©
16
UML diagram
MouseAdapter
Applet
CatGame
Mouse
paint()
DAAD project „Joint Course on OOP using Java“ ©
Graphics
17
The main class
CatGame
. . .
init()
addCircle()
update(Graphics g )
paint(Graphics g)
DAAD project „Joint Course on OOP using Java“ ©
18
Development process of
‚Mouse in a Maze‘
Requirements analysis
Design
Implementation and test
DAAD project „Joint Course on OOP using Java“ ©
19
Implementation phase
We use 3 steps in the implementation (In
fact 3 applets are developed. Each applet is
independently tested):
1.Circle
2.Circles
3.CatGame
DAAD project „Joint Course on OOP using Java“ ©
20
Testing
The applets Circle and Circles are very
simple for the testing.
The applet CatGame is more complicated.
We should complete game to see the
picture of the cat.
We should to adjust all parameters to fit
everything in the window of applet
Demonstration
DAAD project „Joint Course on OOP using Java“ ©
21
Critics of the implementation
The structure of classes should be better
organized.
UML diagrams could be presented with
more details.
Program should be more secure (the
private variable should be used)
. . .
DAAD project „Joint Course on OOP using Java“ ©
22