Docsity

Object Oriented Software Construction - Lecture Slides | CS 241, Exams of Computer Science

Toggle sidebar
bg1
1
ObjectObject--oriented software constructionoriented software construction
Analysis/Requirements: What am I doing?
Design: Which classes and methods?
Implementation: How do I do it?
Testing: Does it work?
Maintenance: I just turn it in, right?
Software Construction ISoftware Construction I
zProgramming is not just coding and debugging!
zAnalysis
– English description of what system models,
to meet a requirement or specification
– Usually involves working with non-programmer
to develop detailed specifications
Di
Mtit!
Analysis
Implementation
Design
Testing
Maintenance
Waterfall model of so ftware develop ment
58
Wright State University, College of Engineering
Dr. T. Doom, Computer Science & Engineering CS 241
Computer Programming II
z
D
es
i
gn:
M
easure
t
w
i
ce, cu
t
once
!
–divide & conquer: system is composed of smaller subsystems which in
turn may be composed of even smaller subsystems
zOOP, 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
zOften flowcharts in procedural languages and UML diagrams in OOP
Software Construction IISoftware Construction II
zImplementation
– Pick a language
– emphasize good problem decomposition,
well structured design, and readable,
well-documented programming style
–ma
y
need to backtrack and redesi
g
n
Analysis
Implementation
Design
Testing
Maintenance
Waterfall model of so ftware develop ment
59
Wright State University, College of Engineering
Dr. T. Doom, Computer Science & Engineering CS 241
Computer Programming II
yg
zTesting
– submitting input data or sample user interactions and seeing if
program reacts properly
– typically done in stages, starting with individual components and
working up to subsystems, and eventually the entire program
–bugs: errors in code or design
–debugging: process of removing program bugs
pf3
pf4

Partial preview of the text

Download Object Oriented Software Construction - Lecture Slides | CS 241 and more Exams Computer Science in PDF only on Docsity!

ObjectObject--oriented software constructionoriented software construction

Analysis/Requirements: What am I doing? Design: Which classes and methods? Implementation: How do I do it? Testing: Does it work? Maintenance: I just turn it in, right?

Software Construction ISoftware Construction I

z Programming is not just coding and debugging! z Analysis

  • English description of what system models, to meet a requirement or specification
  • Usually involves working with non-programmer to develop detailed specifications D i M t i t!

Analysis

Implementation

Design

Testing Maintenance Waterfall model of software development

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 58

z Design: Measure twice, cut once!

  • divide & conquer : system is composed of smaller subsystems which in 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 z Often flowcharts in procedural languages and UML diagrams in OOP

Software Construction IISoftware Construction II

z Implementation

  • Pick a language
  • emphasize good problem decomposition, well structured design, and readable, well-documented programming style
  • may need to backtrack and redesign

Analysis

Implementation

Design

Testing Maintenance Waterfall model of software development

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 59

y g z Testing

  • submitting input data or sample user interactions and seeing if program reacts properly
  • typically done in stages, starting with individual components and working up to subsystems, and eventually the entire program
  • bugs : errors in code or design
  • debugging : process of removing program bugs

Software Construction IIISoftware Construction III

z Maintenance

  • keep the program working and current
  • Good documentation is a must, as is a good initial design

z Software development not usually as linear as waterfall model

  • Spiral method: go back during implementation to change the design,

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 60

p g g p g g , go back during testing and debugging to change implementation

  • Incremental development (accretion): emphasis on designing, implementing, and testing a small version of the system, and then repeating these steps for larger and larger versions of the system
  • Extreme programing: emphasis on teams, flexibility, and writing test code first!

z What makes a program “good” or a “horror”?

What makes code easy toWhat makes code easy to

test/debug/maintain?test/debug/maintain?

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 Cl C h i th d t hi h th th d f l d l ith ifi

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 61

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 without necessitating code change in the other method.
  • Classes should have loose coupling

Pre/Post conditionsPre/Post conditions

z Precondition : A condition that must be true about the state of the system (input parameters, instance variables, etc.) before executing a method

  • Example: say we want a letter from a-z. We use type char for the input parameter. Our precondition is that the character is from a-z and not punctuation or some other legal value of type char. z Postcondition : condition that must always be true just after the execution

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 62

of a routine.

  • Example: the result of a factorial operation must always be greater than one

z Checking input from users is generally a necessary step in satisfying method preconditions

Development: Implementation & TestDevelopment: Implementation & Test

z For most programmers, these two steps are be inseparable and cyclic z For each class

  • Determine the instance variables
  • Write psuedocode for the methods
  • Write test code for the methods
  • Implement the methods

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 66

  • 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

Requirements for Text BattleshipRequirements for Text Battleship

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:

  • Rows are alphabetic: A-E
  • Columns are numeric: 1-
  • ‘~’ represent unknown sea
  • ‘ ’ represent an previously targeted miss

1 2 3 4 5 A ~. ~ ~ ~ B ~ x ~ ~ ~ C ~ ~ ~ ~ ~ D * * *

Wright State University, College of EngineeringDr. T. Doom, Computer Science & Engineering CS 241Computer Programming II 67

-. represent an previously targeted miss

  • ‘x’ represents a previously targeted hit
  • ‘*’ 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 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.
  • Show the surviving ship locations! (use ‘o’ to display).

D * * * ~ ~ E. ~ ~ ~ ~