programming techniques course

42
© Copyright Eliyahu Brutman Programming Techniques Course ןןןןן ןןןןן ןן ןןןן' ןן ןןןןןן( 1939-2001 ) ןןןן ןןן ןן ןןןןן, ןןןןןןן ןןןן ןןןןן ןןןןן ןןןןןןןןןןן ןןןן, ןןן ןןן, ןןןן ןןןןן, ןןןן ןןןןן ןןןןן ןןןןןןןן ןןןןן, ןןן ןןןןן ןןןן ןןןןןןןןן, ןןןןן, ןןןןן ןןןןן, ןןןןןןןן ןןןןן ןןןן

Upload: paley

Post on 05-Jan-2016

19 views

Category:

Documents


0 download

DESCRIPTION

Programming Techniques Course. מוקדש לזכרו של פרופ' לב ברוטמן (1939-2001) חוקר בעל שם עולמי, ממייסדי החוג למדעי המחשב באוניברסיטת חיפה, איש מדע, מורה ומחנך, גידל דורות לאהבת המתמטיקה והמדע, תוך קידוש ערכי המצויינות, המופת, הכבוד ההדדי, הסובלנות ואהבת האדם. Version 1.0. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques Course

(1939-2001) מוקדש לזכרו של פרופ' לב ברוטמן

חוקר בעל שם עולמי, ממייסדי החוג למדעי המחשב באוניברסיטת חיפה, איש מדע, מורה ומחנך, גידל

דורות לאהבת המתמטיקה והמדע, תוך קידוש ערכי המצויינות, המופת, הכבוד ההדדי, הסובלנות ואהבת

האדם

Page 2: Programming Techniques Course

© Copyright Eliyahu Brutman

Chapter 1 –Software Engineering

Version 1.0

Page 3: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 3

Table of contents

About the lecturer Course objectives Some administrative stuff

SW Engineering Well known models Object Orientation The development process Tools The industry – current situation Exercise

Page 4: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 4

Course Objectives

About the lecturer Why am I here? Why are you here? Course objectives

Object Orientation – how it evolved

Modeling – Analysis, Design, Implementation

Tools and the industry

C++ as an OO Programming Language Through all its capabilities and features Learn and use

Understand Object Orientation, and what characterizes it

Understand why it is good, and why so much money is invested in it

Page 5: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 5

Administration

Lecture days and hours Practices Assistance Labs Homeworks Grades Exam

We are here for your success!!

Page 6: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 6

Credits & Bibliography

Dr. Shimon Cohen –

- מהדורה - הכרה אינטואיטיבית של המודל תכנות מונחה עצמים1999 אפריל 1.1

Rational Software

UML and the Unified Process – Ivar Jacobson, from Rational Worldwide Software Symposium – speaker support notes

Bibliography

C++ Primer - Stanley B. Lippman, Josée LaJoie

Inside the C++ Object Model - Stanley B. Lippman

Visual C++\MFC - מדריך מקצועי - Meir Sela

“Effective C++” – Scott Meyers

“More Effective C++” – Scott Meyers

“Effective STL” – Scott Meyers

WEB

Page 7: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 7

SW Engineering

What is it all about?

Is it engineering at all? Who cares about it?

Managers

Quality assurance personnel

Customer Why do it?

Save money

Quality product, standards

Page 8: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 8

The Development Process

What is a development process? Why a development process? The development process

Requirements gathering

System analysis

System design

Implementation

Unit testing

Integration

System testing

Delivery

Maintenance

Page 9: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 9

Development Process - Waterfall

Waterfall

Page 10: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 10

Development Process – Spiral Iterative

Iterative, spiral

Page 11: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 11

Structured Programming

Structured Programming

Procedures

Data

Page 12: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 12

Structured Programming

Traditional structured paradigm:

Identify the algorithm (functions) required to solve the problem: Functional decomposition Control flow

Identify the data structures needed by the functions.

Make them work together Implement functions using/modifying the data

Page 13: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 13

OO Programming

Object Oriented Programming

Methods

Data

Objects

Page 14: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 14

Object Oriented Programming

Object-Oriented paradigm:

Identify the abstract objects (data) that represent the problem domain.

Identify the abstract operations supported by the objects, i.e., define the interface to the objects.

The problem solution is a sequence of calls to objects.

Objects exchange messages with one another

Page 15: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 15

Lets Examine An Example

Phone Book

Requirements

Entry for each person / business

• Name, phone number, address

Operations

• Add/remove/modify name/phone number/address Well designed programs are more reusable and maintainable. The more you invest in infrastructure the less problems you will

have with later changes

Invest a lot in thinking, for gathering generic requirements

Page 16: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 16

New or changed

requirements

New or changed

system

Software EngineeringProcess

What Is a Development Process?

For each iteration define who is doing what, when and to produce which result

Page 17: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 17

Creating the Unified Process

Functional testingPerformance testingRequirements mgmtConf. and change mgmtBusiness engineeringData engineeringUI design

Rational Unified Process 5.01998

Rational Objectory Process 4.11996-1997

Objectory Process 1.0-3.81987-1995

The Ericsson Approach

The Rational Approach UML

Page 18: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 18

Overview of the Unified Process

The Unified Process is

Iterative and incremental

Use case driven

Architecture-centric

Why RUP – Rational Unified ProcessThere are other methodologies …

RUP was designed by the Trio: Ivar Jacobson, Grady Booch, James Rumbaugh

RUP is fully integrated with UML and “Rational Rose”

Page 19: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 19

RUP

BuzzwordsRUP – Rational Unified ProcessUML – Unified Modeling Language

ToolsRational Rose / Rhapsody / XDE – CASE toolVisio – Drawing++ tool

RUP: Rational Unified ProcessProcess’s Workflows Requirements Analysis Design Implementation Testing

Page 20: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 20

Lifecycle Phases

time

Inception Elaboration Construction Transition

Inception Define the scope of the project and

develop business case

Elaboration Plan project, specify features, and

baseline the architecture

Construction Build the product

Transition Transition the product to its users

התחלהעיבוד מפורט בניה/יצירה העברה

Page 21: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 21

Major Milestones

time

Vision Baseline Architecture

InitialCapability

Product Release

Inception Elaboration Construction Transition

Page 22: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 22

The Birth Of OO

Projects size got larger Complexity increased More difficult for maintainability and evolution

=> More expensive

Looking for techniques for reducing complexity, increasing code reuse, more intuitive, unified technique for all development process activities, etc.

Page 23: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 23

Object Oriented Objectives

To enable coping with complex and scaleable projects, Object Oriented provides tools for:

Project design and modeling:

Enables understanding a project’s structure, the components it is built from, their relationships and roles.

Reflecting the real world in a better way.

Unified technique through all project stages

Fast “ramp up” into project

Reducing dependencies between components:

An internal component change should not effect the entire project.

Parallel development, independent

Page 24: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 24

Object Oriented Objectives – cont’d

Code reusability:

Saves development time – each task is developed only once and is used by all required components.

Enables reasonable maintainability – any change, addition or bug fix in this task will be performed once, affecting all components using this code.

Creation of flexible and scaleable projects:

Enabling coping with future changes and additions.

Page 25: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 25

A Bit of History

Time: 1962 Place: Norwegian Computing Center, Oslo Project on simulation of ship movement in fjords

Many kinds of ships, each with its own characteristics… Difficult to distribute the work within team

Team member responsible for Kind of boats?

• Must add code to every function Particular operation?

• Must be expert in all boat kinds

Page 26: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 26

A bit of history (cont.)

Difficult to share code between boat types Difficult to add new boat types and operations Difficult to maintain Solution: group the ships into classes

Each class of ships type has its own data and behavior Simula 67 language

Page 27: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 27

Object Oriented

A System:Is a collection of objects interacting with each other through message passingRelating to each other via some relationship

Is-part-of relationship Is-a relationship Referring-to relationship

Achieved by Containment Aggregation Association Inheritance

For instance: A book contains many pages …

Page 28: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 28

Msg

Msg

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Msg

Msg

Msg

Msg

Message Passing

Synchronous A-Synchronous

Page 29: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 29

Objects

An object:

Is a self contained entity With its own characteristics Reflected via:

• Attributes• Operations• Inter-relationships• More…

An operation is invoked as a result of message passing

The operation is intended to take care of the sent message

Page 30: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 30

An Object

Object

Method

Method

Method

Method

Msg

Msg

Msg

Msg

Msg

Msg

Msg

Msg

Msg

Msg

Page 31: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 31

An Object

ObjectDraw)...(

Count)(

M1)(

M2)(

Int X

Float Y

Looks like:

Page 32: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 32

Relationships

ObjectDraw)...(

Count)(

M1)(

M2)(

Int X

Float Y

Obj BMethod

Method

Obj AMethod

Method

Object “Part of” relation “Reference to” relation

Pointer

Page 33: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 33

World Entities

An entity has

Characteristics

Operations

Responsibilities

Behavior

Relationships to other entities

Invariant state

May have an internal life cycle So we pack all this into one “package”, and we call it a class It is more intuitive, since we as human beings have similar view

of the world

Classification, characterization, relationship description, etc.

Page 34: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 34

What did we achieve?

Described the problem in terms natural to the problemPre-OO, we talked in terms of ints and floats, like the computerNow we can talk in terms of boats and maneuvres

Partitioned the problem into encapsulated sub-problems with well-defined interfaces

Adding new boat types is easy And so is changing boat behavior

Page 35: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 35

Classes – cont’d

Objects - Instances of the classThe class

Different Ships objectsThe Ship class

Length

Coordinates

Go

Stop

35

123, 456

Go

Stop

65

222,333

Go

Stop

Page 36: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 36

Classes – cont’d

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Object

MethodMethodMethodMethod

Class

Page 37: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 37

Inheritance

Inheritance Tree(definition)

Page 38: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 38

Inheritance Tree Example: Employee

Boat

SailBoat MotorBoatPaddleBoat

AircraftCarrier

Page 39: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 39

Inheritance - Main Concepts

When a class inherits from a base class, it contains all functionality and characteristics of its base

A derived class can expand its specifications by:

Adding new data

Adding new functionality

Overriding the inherited functionality

Page 40: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 40

Employee Inheritance - Tree Revisited

Boat

getLocation()move(Env)turn(Dir)

Location……

SailBoatfloat sailAreamove(Env)turn(Dir)

MotorBoatfloat engineVolumemove(Env)turn(Dir)start(Eng)

Engine……

Page 41: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 41

ObjectsWhat Are They Good For ?

Understand the problem

a natural way of looking at things (problems) Software Engineering

Encapsulation helps to achieve the goals of Parallel Development

Each object is defined independently

Why is it better to view the system as

a collection of objects ?

Page 42: Programming Techniques Course

© Copyright Eliyahu Brutman

Programming Techniques – Chapter 1 - 42

Objects - Encapsulation

Hiding implementation

What is it good for?

Can you give an example? De-coupling / Decomposition

For reuse

For easier modifications, implementation free Example:

Replace float sailArea with float sailAreas[]