You are on page 1of 26

Introduction

Software Engineering with OOP

Software Crisis

Common software systems behavior


Does not provide required functionality Is over budget with respect to time and money and computer resource usage Not adaptable to changing user needs

Why?
User needs are ill-specified Complexity of interactions grows multiplicatively Human cooperation limits Programming is difficult

Software Engineering

Goal
Ease

the development of reliable, flexible, economical software

Techniques
Group

management Complexity management Measuring software quality

Caveat
Throwing

more people at a problem isnt always the best way to fix it

Software Development Basics


Requirements Analysis
Specifications

What is the problem?


Problem statement for programmers

System Design Program Design


Program Implementation Testing

What is the solution?

Problem Domain

What are the mechanisms that best implement the solution? Implementation How is the solution constructed? Domain
Is the problem solved?

Delivery
Maintenance

Can the customer use the solution?


Are enhancements needed?

Over 50% of development costs!

C++

Designer
Stroustrup

Purpose
To

implement software tools more quickly, reliably, and economically

Principal features
Implements

most of C (superset) Supports object-oriented programming Reusable software components that have both attributes and behavior i.e., objects

Where Do We Go From Here?


Machine organization, programming, translation software, programming environments, data representations, terminology, history, software engineering, object-oriented design [1] C++ fundamentals, C++ programs, C++ objects, input, output [2] Modifying objects, arithmetic, operator precedence, strings [3] Control constructs, Boolean objects, programming logic, conditional execution, switch statement [4.1-4.5] Repetition, looping, for and while and do loops [4.6-4.12] Functions, library programs: iostream, iomanip, fstream, generating and using random numbers [5] Programmer-defined functions, parameters, pass by value, pass by reference [6] Classes: programmer-defined data types, constructors, object-oriented design and analysis [7] Inheritance [8]

A C++ Program
// Canonical first program #include <iostream> Pre-processor directives #include <string> using namespace std;
A using directive

int main() {
cout << "Hello world!" << endl; return 0;

Software Engineering Goals


Reliability An unreliable life-critical system can be fatal Understandability Future development is difficult if software is hard to understand Cost Effectiveness Cost to develop and maintain should not exceed profit Adaptability System that is adaptive is easier to alter and expand Reusability Improves reliability, maintainability, and profitability

Software Engineering with OOP


Identity Data are organized into (named) objects Abstraction Extract the relevant properties while ignoring inessentials Divide an object into smaller modules (modularity) Simplify to make it easier to understand Classification (Hierarchy) Ranking or ordering of objects based on some relationship between them Encapsulation Couple the data PLUS the operations on that data together; Also, hide and protect essential information (implementation details) behind a controlled interface i.e., information hiding. Inheritance Ability to create new classes based on existing ones Polymorphism Exhibiting the same behaviour differently on different classes or subclasses Persistence

Abstraction

Extract the relevant object properties while ignoring inessentials

Defines a view of the object

Example - car

Car dealer views a car from selling features standpoint

Price, length of warranty, color, Size of the oil filter, type of spark plugs, How fast does it go, fuel consumption, etc
Price?

Mechanic views a car from systems maintenance standpoint

Driver views a car from usability standpoint

Oil change?

Encapsulation

Steps Decompose an object into parts

Data and Methods that operate on them go together Information Hiding is hiding implementation details; encapsulation (a language construct) is not the same thing as information hiding (a design principle), although it implements it

Hide and protect essential information (implementation details)

Supply interface that allows information to be modified in a controlled and useful manner

Internal representation can be changed without affecting other system parts


Example - car radio Interface consists of controls and power and antenna connectors The details of how it works is hidden To install and use a radio

Do not need to know anything about the radios electronics

Modularity

Dividing an object into smaller pieces or modules so that the object is easier to understand and manipulate Most complex systems are modular Example - Automobile can be decomposed into subsystems

Cooling system

Radiator

Thermostat

Water pump

Maneuvering

Steering
Battery

Wheels
Starter

Brakes
Spark plugs

Ignition system

Hierarchy

Hierarchy
Ranking

or ordering of objects based on some relationship between them

Help us understand complex systems


Example

- a company hierarchy helps employees understand the company and their positions within it

For complex systems, a useful way of ordering similar abstractions is a taxonomy from least general to most general

OO Design and Programming

Object-oriented design and programming methodology supports good software engineering

Promotes thinking in a way that models the way we think and interact with the real world

Example - watching television

The remote is a physical object with properties

Weight, size, can send message to the television

The television is also a physical object with various properties You are also a physical object

With eyes, ears, etc.

Objects

An object is almost anything with the following characteristics


Name

(Identity) (data and function members)

Properties The

ability to act upon receiving a message


message types
Directive to perform an action (function member) Request to change one of its properties (mutator) Request to get the value of one of its attributes (accessor)

Basic

All you need is love objects?

Objects are implementations of Abstract Data Structures But to make programs, we also need algorithms! Algorithms + Data Structures = Programs
Nicklaus

Wirth (creator of Pascal)

Whats an Algorithm?

A predetermined series of instructions for carrying out a task in a finite number of steps I.e., Baking A Cake! Two commonly used tools to help document the program logic (the algorithm): Flowcharts and Pseudocode. Generally, Flowcharts work well for small problems but Pseudocode is used for larger problems

Flowchart: Symbolic Representation of Algorithms

Flowchart: A graphic representation of an algorithm, often used in the design phase of programming to work out the logical flow of a program

Some Control Structures


Sequence Selection Repetition (Looping)

What is pseudocode?

Pseudocode!

Pseudocode is basically short, English phrases used to explain specific tasks within a program's algorithm. Pseudocode should not include keywords in any specific computer languages. Indentation can be used to show the logic in pseudocode as well. Writing pseudocode WILL save you time later during the construction & testing phase of a program's development lets you think out the program before you code it. Consists mainly of executable statements

Why is pseudocode necessary?

How do I write pseudocode?

If you cant write it in pseudocode, you wont be able to write it in C++!

Original Program Specification: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Variables required (names and types): int1: (integer) to store first integer int2: (integer) to store the second integer sum: (integer) to store the sum of the numbers

Pseudocode: Prompt the user to enter the first integer int1 Prompt the user to enter a second integer int2 Compute the sum of the two user inputs sum = int1 + int2 Display an output prompt that explains the answer Display the result

Error, error does not compute!

Syntax Errors Typing Errors

Syntax refers to the structure of a program and the rules about that structure

Errors in spelling and grammar (syntax).


Doag. Bites, Man

You can use the compiler or interpreter to uncover syntax errors. You must have a good working knowledge of error messages to discover the cause of the error.

Semantic Errors Logic or Meaning Errors

Errors that indicate the logic used when coding the program failed to solve the problem.

Man bites dog.

You do not get error messages with logic errors. Your only clue to the existence of logic errors is the production of wrong solutions.

Run-time Errors (Exceptions)

Code does something illegal when it is run (hence runtime)

E.g., divide by zero

In-Class Exercise

Write an algorithm that will, given the current date, find the date of the next day.

Pseudo-code Solution

1) Get the current date - Get the current month, day, and year in numerical form 2) If month is 2, If day = 29 or day = 28 and it's not a leap year increment month else increment day else if month = 1,3,5,7,8,10,12 If day = 31 increment month else increment day else if month = 4,6,9,11 If day = 30 increment month else increment day 3) Report "new" date [month, day, year] Increment Day add 1 to current day Increment Month if month = 12 increment year else add 1 to current month day = 1 Increment Year add 1 to current year month = 1 Leap Year divisible by 400 or divisible by 4 but not 100

In-Class Exercise

Write the pseudo-code for a Game of Monopoly Write the pseudo-code for one persons move as a procedure Draw a flowchart representing one persons move as a procedure

Pseudo-Code Solutions

This is the pseudocode for a Game of Monopoly, including one person's move as a procedure:

Main Procedure Monopoly_Game Hand out each player's initial money. Decide which player goes first. Repeat Call Procedure Monopoly_Move for next player. Decide if this player must drop out. Until all players except one have dropped out. Declare the surviving player to be the winner. Procedure Monopoly_Move Begin one's move. Throw the dice. Move the number of spaces on the board shown on the dice. If the token landed on "Go to Jail," then go there immediately. Else if the token landed on "Chance" or "Community Chest," then draw a card and follow its instructions. Else follow the usual rules for the square (buying property, paying rent, collecting $200 for passing "Go", etc.). End one's move.

Flowchart Procedure Solution

One Persons Move:

You might also like