1. CS2006 - Data Structures I
Chapter 2
Principles of Programming
&
Software Engineering
2. 2
Topics
Software Life Cycle
Abstraction – Abstract Data Type
OO Design
Encapsulation
Inheritance
Polymorphism
3. 3
Introduction
How do you write a Java program in COSC
1046/1047?
Old fashion way
Write code
Compile
Check syntax
Run
Check logic
How about a large
project with a team?
4. 4
Introduction
A better way
Systematic way (Structured approach)
Specify problem
Analyze
Design
Implement
Test
Maintain
5. 5
Introduction
SW Engineering:
Computer science branch that provides
techniques for development of computer
programs
Systematic approach to analyze, design,
implement, and maintain software
Uses CASE tools (Computer Aided Software
Engineering)
6. 6
The Software Life Cycle
1. Specification
2. Design
3. Risk Analysis
4. Verification
5. Coding
6. Testing
7. Refining
8. Production
9. Maintainence
7. 7
1. Specification & Analysis
Specification
A contract between customers and
developers
Not how, but about what
May involve construction of a prototype
program to get more details from users.
8. 8
1. Specification & Analysis
Example:
“design and implement a software to store a
library’s catalogue of books”
Input (partial):
Librians enter new books as they arrive
Library users enter search
keys to search through our list
9. 9
1. Specification & Analysis
Process:
Add new book
Search for books
Output:
Show all the info about a book
Requirements
Are there any time/space/performance constraints
10. 10
2. Design
Given:
Clear & detailed specification of all aspects of
the problem
Output:
Design for a solution to the problem
(algorithm) - UML diagrams (about How)
Idea:
Use modular design
Divide & conquer
Divide the problem into smaller manageable parts.
12. 12
3. Risk Analysis
Risks are primarily business related but
can be personal as well.
Not an important issue for this course.
13. 13
4. Verification
Determining the degree to which a software
product fulfills its specification
Formal, theoretical methods for proving
algorithm correctness
14. 14
5. Implementation (Coding)
Coding
Translating the algorithm into a particular
programming language & removing syntax
errors
Should not start unless previous stages are
well defined
15. 15
5. Implementation (Coding)
Bottom-up implementation:
First implement submodules, then modules
Top-down implementation:
Implement a module before implementing its
submodules A
S3
S2
S1
16. 16
6. Testing
Careful design of test data is important
Valid (In-range) data
Invalid (out-of-range) data
Random values of data
Test several times on different
circumstances
Any modification in the program needs re-
testing
17. 17
7. Refining the Solution
Usually involves increasing the
"robustness" of a solution.
Example: assume that the input will be
integers between 0 and 1000.
During this step code would be inserted to actually
test the input values.
19. 19
9. Maintenance
Correct errors not discovered during
testing
Add more features
Enhance existing features
Modify to suit the user better
20. 20
Abstraction & Information Hiding
Example: Cars brakes
Client
box
Car
Black box
Push
the brakes
My interior design is
using
Cylinder brakes
or
Drum brakes
Brake pedal pushed
Car stop
22. 22
Abstraction
Abstraction separates the purpose of a
module from its implementation.
Example: Sorting
Client
box
Sort
Black box
Sort this data
please,
I don’t care
how you do it
I can sort data into
ascending order without
you knowing how
Unsorted data
Sorted data
23. 23
Procedural Abstraction
Procedural Abstraction is the process of
separating the purpose of a method from
its implementation.
Once written the method can be used without
any knowledge of how it is implemented - only
need to know the parameters.
Example: ??
24. 24
Abstract Data Types
ADT - a collection of data along with a set of
operations that can be performed on that
data.
No details about how the data is stored or how
the operations on the data are implemented.
An ADT is a general description of the design of
a module with no details.
26. 26
Abstract Data Types
Data Structure - the implementation of an
ADT in a programming language.
The details of data storage and how
operations are performed are crucial parts of a
data structure.
27. 27
ADT List
Any List in general will allow the following
operations:
Create an empty list
Destroy a list
Determine whether a list is empty
Determine the number of items in a list
Insert an item at a given position in the list
What else?
28. 28
Object-Oriented Design
Three elements to OOD:
Encapsulation - combining data and
operations within one object.
Inheritance - objects can inherit data and/or
methods from other objects.
Polymorphism - objects can determine
operations at execution time.
Every object knows its "true" type regardless of type
casting
29. 29
Object-Oriented Design
Produce a collection of objects that have
behaviours
How to do
Identifying the objects in the problem
UML
Contents of Software Engineering (cosc 3506)
30. 30
Object-Oriented Design
Consider the nouns and verbs in the
problem domain
Create a ATM machine which allow user to retrieve,
deposit, transfer and check balance of their accounts
ATM
Account: account
Open ()
Close()
Account
Type: String
Amount: double
transfer (int )
checkBalance()
retrieve
deposit ()
31. 31
Review
The first phase of the life cycle of software
is the ______ phase.
design
risk analysis
specification
coding
32. 32
Review
The syntax errors of a program are
removed during the ______ phase of the
program’s life cycle.
verification
coding
testing
refining
maintenance
33. 33
Review
Which of the following is an example of a
logical error?
an algorithm that calculates the monthly
payment of a loan displays incorrect results
an array subscript in a program goes out of
range
a program expects a nonnegative number but
reads –23
the beginning of a while loop is written as
“whille” instead of “while”
34. 34
Review
During the design phase of the software
life cycle, the program is divided into
______.
invariants
loops
Modules
prototypes
35. 35
Review
CASE tools refers
Use Case for Applications
Computer Aided Software Engineering
Common Agent Software Engineering
Contact Assistant Software Engineering
36. 36
Review
A prototype program is created during the
______ phase of the software life cycle.
design
specification
Coding
testing
37. 37
Review
Which of the following is not a goal of
Software Engineering:
(a) Make Complex Software/Systems Manageable.
(b) Create code implementations which are as big as
possible.
(c) Coordinate large number of developers.
(d) Handle complex software systems.
38. 38
Review
A(n) ____ is a collection of data and a set
of operations on the data.
method
exception
abstract data type
data structure.
39. 39
Review
With ______, objects can determine
appropriate operations at execution time.
encapsulation
inheritance
Polymorphism
information hiding.
40. 40
Review
Object-oriented design identifies objects
by focusing on the ______ in the problem
statement.
nouns
verbs
Adjectives
adverbs