Title: Software engineering principles
1- Software engineering principles
- In this course you will learn
- how to apply good software engineering
principles - how to represent and manipulate collections of
data - object-oriented design using the C language
- Two important concepts are
- data structures represent information
- algorithms are used to manipulate information
- In this course you will gain experience
- designing and analyzing algorithms and data
structures - writing, debugging, and testing programs
2Phases of the software life cycle
3spiral model (Boehm)
Phases of the software life cycle
1. program analysis specification (Nyhoff)
5. maintenance (Nyhoff)
internal (comments)
external (man pages)
4. testing, execution, debugging (Nyhoff)
2. design (Nyhoff)
3. coding (Nyhoff)
4Our goals for all of our software Good software
should be all of these things algorithmically
efficient easy to use well structured well
tested easy to modify In order to achieve the
development of good software, design is very
important. In this course we will focus on
software design, in particular on the design of
data structures and the algorithms that
manipulate them.
5- Modularity (abstraction)
- Decompose programs into small, re-usable modules
that are - highly cohesive elements within a module are
closely related to each other - loosely coupled one module does not depend
heavily on the elements within another module - A module is a collection of related data and
operations that are either - public accessible to clients that use the
module - private inaccessible to clients
- Encapsulation or information hiding keeps the
internal workings of a module behind an external
public interface
6- Object oriented design
- A class in C or Java corresponds to a module
- just one type of data and associated operations
- exports some data and operations to other
classes - imports some data and operations from other
classes - A driver program tests the class implementation
- The data and operations are members of the class
- member functions are called methods
- public methods and data are exported (visible)
- private methods and data are not externally
visible - protected methods and data also exist (more
later)
7- Bank account object oriented design
- Design a program for a banking system
- each account has a unique 4-digit ID number
- the bank must be able to open and close accounts
- customers can deposit or withdraw and obtain the
balance for an account - accounts must have a non-negative balance
- Two classes, one for accounts and one for the
bank - Account class exports public operations
- Bank class imports Account public operations
- Bank class exports its public database operations
8- Account class - object oriented design
- The Account class is used by the Bank class for
customers - It has the following public interface
- create a new account (account ID, customer
name, opening balance) - deposit (amount)
- withdraw (amount)
- get the balance for account
- get the ID for account
- get the customer name for account
9- Bank class - object oriented design
- The Bank class is used by clerks
- It has the following public interface
- create a new collection of N accounts
- open a new account (customer name, opening
balance) and assign it an ID - close a existing account (ID)
- make a deposit (ID, amount)
- make a withdrawal (ID, amount)
- get account balance (ID)
10- (Class) Invariants
- Each module (class) has a set of rules called
invariants - These are properties of the data (objects) in the
module - must hold after an object is constructed
- must hold until the object is destroyed
- might not hold while an object is being modified
- but must hold after the modification is complete
- Invariants are part of the public interface
- the module (class) relies on the invariants
being true - other modules (classes) also rely on them being
true - every implementation must guarantee the
invariants
11- Class invariant for Account class
- There are three rules for Accounts
- an account has a valid ID, customer name, and
balance - 1000 lt Account ID lt 9999 (the 4-digit ID rule)
- balance gt 0 (the no negative-balance rule)
- Class invariant for Bank class
- There are four rules for Accounts
- the number of accounts lt N (the not too many
rule) - IDm ? IDn if m?n (the unique ID number rule)
- accounts do not exist until opened
- accounts exist until closed
12- Pre-conditions and Post-conditions for methods
- A pre-condition is a rule or condition that
- is required to be true before a method is
invoked - otherwise nothing is promised by the method
- A post-condition is a rule or condition that
- will be true after a method has been invoked
- may or may not be true after the invocation if
the pre-condition was not true (garbage
in/garbage out) - These specify a contract between the client
programmer and the software designer - The class invariant is implicitly part of the
pre-condition and post-condition for all methods
in a class
13Account class pre-conditions and
post-conditions Pre-condition for the withdraw
method in Account The following must be true
before a withdrawal zero lt amount requested lt
current balance Post-condition for the withdraw
method in Account The following will be true
after a withdrawal new balance old balance ?
amount requested
14- Program Testing
- Before implementing modules we design a plan for
testing - test the software using expected data
- test the software using boundary values
- test the software using unexpected data
- For a class (such as Account)
- test all public methods to ensure that
postconditions are true after invocation - test that the class invariant is true at all
times - Testing cannot prove that an implementation is
correct, only that no bugs have been found during
testing
15Types of files used in the C compilation
process the module interface is described in a
header file class.h the source code is in a
source file class.cpp include files are the
header files for other modules module.h the
compiler creates object code in an object file
class.obj pre-compiled code is an archive file or
library file linking and loading object and
library files produces an executable file .dll
(or some specified name) Unix keeps build scripts
in a make file makefile (Later well see template
files class.template)
16The compilation process Each step of the
translation process gets closer to the underlying
machine representation of a program Source code
is the highest level, which abstracts away as
much as possible to promote machine
independence Object code has most of the
machine-specific details except for where
instructions and data are stored in memory The
executable links object code for all of the
modules into a single program with each
instruction or data item assigned to a particular
location in memory Preparing a large program for
execution usually requires that many source code
files be compiled and linked together with
library code to form an executable
17- The Build process
- There are many steps in the translation process,
so we look for tools that will automate some of
the steps - These are often called build scripts because they
specify the compilation steps required to build a
new version of a program - One of the simplest ways to build programs in
Unix (and other systems) is the make command - only re-compile parts of the program that have
changed (reducing compilation time) - figure out the right order to do each step
(reducing errors) - may partially automate testing as part of the
build
18Visual Studio C In Lab 1 you will learn how to
build a program (project) using Visual Studio In
real-life situations projects are often
complicated sets of many source and header files
that must be compiled and linked together. Visual
Studio C has mechanisms similar to the Unix
make command that automate this process.
19- Implementation (declaration vs. definition)
- The Account class has files account.h
account.cpp - account.h has the class declarations for the
public and private parts of the class - account.cpp has the class definitions
implementing the class operations (methods) - Documentation standards (required!)
- all files specify their name, author, date of
creation and date of last modification - every file has a short description of its
purpose - the class invariant is in both files
- pre-conditions and post-conditions are in both
files
20Types of files used in the Java compilation
process all source code for a module is in a
source file module.java include files in a module
are other modules utilized by a module the
compiler creates object code in an class file
module.class linking and loading happens at run
time, not as part of the compilation process Java
does its own equivalent of build scripts, but a
makefile approach is OK too