






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Design: Which classes and methods?
Implementation: How do I do it?
Testing: Does it work?
g
Maintenance: I just turn it in, right?
z^
Programming is not just coding and debugging! z^
Analysis
Analysis
English description of what system models,to meet a requirement or specification
-^
Usually involves working with non-programmer
DesignImplementation
Testing
y^
g^
p^
g
to develop detailed specifications
z^
Design:
Measure twice, cut once!
divide & conquer
: system is composed of smaller subsystems which in
Maintenance
Waterfall model of software development
q^
y^
p^
y
turn may be composed of even smaller subsystems^ z^
OOP, system is decomposed into a set of
cooperating objects
Pseudocode
: describe tasks, subtasks, and how they relate
hand-simulation
: desk-check pseudocode by stepping through it
without using a computer
-^
often use diagrams to better communicate the structure of the system
Of
fl^
h^
i^
d^
l l
d UML di
i^
OOP
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
z^
Of
ten flowcharts in procedural languages and UML diagrams in OOP
z^
Maintenance–
keep the program working and current
p^
p^
g^
g
Good documentation is a must, as is a good initial design
z^
Software development not usually as linear as waterfall model z^
Software development not usually as linear as waterfall model•
Spiral method: go back during implementation to change the design,go back during testing and debugging to change implementation
l d
l^
i^
h^
i^
d^
i^
i
-^
Incremental development (accretion): emphasis on designing,implementing, and testing a small version of the system, and thenrepeating these steps for larger and larger versions of the systemE
i^
h^
i^
fl
ibili
d^
i i
-^
Extreme programing: emphasis on teams, flexibility, and writing testcode first!
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
z^
What makes a program “good” or a “horror”?
z^
Abstraction
: The ability to view a complex operation in a simplified form
-^
Good classes are abstract representations of objects in the problem domain
-^
Good utility/library classes have a “functional” problem domain
z^
Method
Cohesion
: the degree to which a method implements a single function
-^
Each method should do a well specified task with no surprises or side-effects
-^
Methods should have high cohesion
z^
Class
Cohesion
: the degree to which the methods of a class deal with a specific
abstraction–
Classes should have high cohesion
z^
Coupling
: the degree to which a method depends upon the specific implementation
of other methods–
Methods that share global data in an array field, for instance, are “coupled”.Neither method can change the way in which the data is stored withoutnecessitating code change in the other method.Classes should have loose coupling
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
-^
Classes
should have loose coupling
z^
Enforce pre/postconditions! public static double divide (int numerator, int denominator) {
if (d
i^
t^
if (denominator == 0) {
System.out.println(“divide error: zero denominator);System.exit(1);
} return (double) numerator/denominator; } // end dividepublic static void main (String[] args) {
System.out.println( divide(3,0) ); } // end method main z^
Assertion statements simplify test code–
Include -ea or –enableassertions runtime/VM flag to enable }^
// end method main
} // end class Main
g
public static double divide (int numerator, int denominator) {
assert denominator != 0;
// requires -ea VM flag
return (double) numerator/denominator; } // end divide
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
}^
// end divide
z^
Identify all the nouns in the problem description / analysis / requirements
Each of these is a
potential
class or object instance
Each of these is a
potential
class or object instance
z^
Refine the list to identify the classes–
Some of the nouns may mean/represent the same thing
-^
Some nouns used may be beyond the scope of the problem
-^
Some of the nouns may represent objects, not classes
-^
Some of the nouns may represent values that can be stored in aprimitive variable and thus do not require a class.
z^
For each putative class–
Determine what the class
knows
instance variables): generally nouns
e e
e w a
e c ass
knows
s a ce va
ab es): ge e a y
ou s
Determine what the class
does
(methods): generally verb phrases
z^
Construct UML diagrams z^
R f
t^
i^
: Come back and impro e
o r design an time!
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
z^
efactoring
:^ Come back and improve your design anytime!
z^
For most programmers, these two steps are be inseparable and cyclic z^
For each class z^
For each class–
Determine the instance variables
-^
Write psuedocode for the methods
-^
Write test code for the methods
-^
Implement the methods
z^
Test each as you develop them
Test the class fully
-^
Debug and reimplement as needed
-^
Move on to the next class.
z^
Develop in iteration cycles z^
Keep it simple s-noun (KISS) z^
Use “stubs” for top down design develop bottom up where necessary
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
z^
Use
stubs
for top-down design, develop bottom-up where necessary
z^
We are going to build a text-based version of the game “Battleship” z^
Our gameboard is going to be 2d 5x5 grid that prints as follows: z^
Our gameboard is going to be 2d 5x5 grid that prints as follows:–
Rows are alphabetic: A-E
-^
Columns are numeric: 1-
1 2 3 4 5 A ~. ~ ~ ~B ~ x ~ ~ ~
‘~’ represent unknown sea
-^
‘.’ represent an previously targeted miss
-^
‘x’ represents a previously targeted hit
B^
~ x ~ ~ ~ C ~ ~ ~ ~ ~D * * * ~ ~E. ~ ~ ~ ~
‘*’ represents a previously targeted vessel that has been sunk.
z^
Input will simply be a coordinate for the next shot (e.g., A2 or E1) z^
There will be two ships size 2 (2x1 or 1x2) and size 3 (3x1 or 1x3) z^
There will be two ships, size 2 (2x1 or 1x2), and size 3 (3x1 or 1x3). z^
The player losses the 5
th^
time that they make a clean miss (“o”).
z^
The player wins if they sink all of the ships before they loose.
Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering
CS 241Computer Programming II
Show the surviving ship locations! (use ‘o’ to display).