Sie sind auf Seite 1von 24

Technical University of Cluj-Napoca Computer Science Department

Object Oriented Programming Techniques

Software Construction

Ioan Salomie Spring 2012

Objective and Overview


Part 1 Software Construction

Problems and Solutions Software development process and Software Construction Design (Heuristics and Best Practices)

Part 2 - Programming Paradigms


Computational Models Fundamental Concepts Sequential Programming Concurrent Programming Parallel Programming Distributed Programming Classes of Algorithms

Problems and Solutions


Problems Problem

Domain and Solution

Domain Solution Understanding the problem Understanding the solution

Problem - Solution
Decomposition / Construction view
Problem Decomposition Solution Construction

Problem Decomposition Construction

Solution

SET Sub-Problems

SET Sub-Problems

Problem - Solution
Details
Problem Domain (PD) processes data

PD Observable results

abstraction process

improve

compare and assess

Algorithms Model Programs Solution Domain (SD)

SD results

USER - queries

Problem - Solution
Modeling gap
Modeling Classical

Semantic Gap

Programs to narrow the gap

Modeling OO Modeling
data abstraction and ADTs class dual meaning

Software development process


Software Construction
Software

development process (also called life cycle)


input: system requirements output: a delivered product CASE tools to automate some tasks

Software

Construction

Software Construction Details


Software

construction - a three phase process:


Detailed design Coding / testing the units Solution composition
Needs System System valid./ Testing

Requirements

Design

Integration / Testing

Software Construction Unit Coding / Testing

Software construction phases


(the phases are presented in bold)
Design Design Design

Level 1 - Overall system design Level 2 - System level design Levels 3,4,5 Detailed Design

The big black box Subsystems and packages Design Level 3 - Subsystem/package level design
for each subsystem: Interfaces, Classes, Relationships

Design Level 4 - Class level design Design Level 5 - Data and function level design
Unit

coding / Unit testing planning / testing (Subsystem level) System integration and testing planning
Integration
9

Design
Objective:

Obtain a good (sub)system


(partial) reuse existent resources; (partial) new resources

Design

iterative try-error and divide and conquer type activity


Breaking Skilled

complexity

top-down or bottom-up approaches

designers

Use heuristics

10

Design dimensions
1. Find abstractions 2. Encapsulate implementation details 3. Hide secret parts (information hiding) 4. Inherit and / or delegate 5. Anticipate changes 6. Keep coupling loose and cohesion strong 7. Look for common design patterns 8. Think of associating things 9. Design for test

11

Design documentation
UML

diagrams CRC cards (class, responsibility, collaboration) Document the design into the code Wiki pages for collaborative designs

12

Desirable design features


External

features Internal features

13

Desirable Design Features


External features
Availability Reliability Performance Fault

tolerant

Maintainability Robustness Security Interoperability Portability Usability Functionality System

integrity

Consistency Efficiency

14

Desirable Design Features


Internal features
Minimal

complexity Ease of maintenance Loose coupling among design (program) parts Extensibility / Scalability Reusability Stratification Standard techniques.

15

Desirable Design Features


Quality Models
Relates external criteria to

external criteria Models


McCall (1977) Boehm (1978) ISO 9126 (1990) Dromey (1996)

16

Software construction Objectives and Features


Analysis, Refactoring, Code tuning
Features External Reliability Performance Failure tolerant Maintenance Portability Interoperability Security Testability Internal Reusable Extensible / Scalable Low complexity Loose coupling High fan-in Low to medium fan-out Completeness Standardized

Existing Code Knowledge, Techniques, Resources, Methods

New Built Solid Code

17

Software Construction Heuristics


Heuristic

[Wikipedia]

a replicable method or approach for directing one's attention in learning, discovery, or problem-solving.
George

Polya - How to solve it

Collection of ideas about heuristics Examples from How to solve it


If you are having difficulty understanding a problem, try drawing a picture. If you can't find a solution, try assuming that you have a solution and seeing what you can derive from that ("working backward"). If the problem is abstract, try examining a concrete example. Try solving a more general problem first (the "inventor's paradox": the more ambitious plan may have more chances of success).

18

Main software construction heuristics


Find real-world objects
Used

in OO software construction Identify objects, their behavior, attributes


What can be done to each object What each object is allowed to do to other objects
Determine

the parts of each object that is visible to other objects Define each objects public interface Exercise
Find

a few related real world objects and answer the above questions

19

Main software construction heuristics


Form Abstractions

a way of approaching complexity Hierarchy of abstractions


Abstraction

At each level underlines important features and ignoring the details Examples
At a given level of abstraction house is a combination of bricks, glasses, doors, roof, timber and mortar At another level - door is an abstraction of a collection of rectangular pieces of materials, knob, small window, etc. At a higher level - village - a collection of houses as a is another abstraction Base

classes as abstractions Interfaces as abstractions


20

Main software construction heuristics


Encapsulate Implementation Details
Implementation

details of object o1 should not be revealed to other objects


Other objects should be only aware of the behavior of o1

Example Encapsulation

and complexity Encapsulation at class level design

21

Main software construction heuristics


Use Inheritance
Find

out the commonalities among objects and organize them in hierarchies The upper abstractions define attributes and behavior that are common to all lower abstractions

22

Main software construction heuristics


Use Delegation
Delegation

is a concept related to aggregation A complex object consists of a set of objects of lower complexity A method that is invoked in association with the complex object delegates parts of its functionality to lower level component objects Example

23

Main software construction heuristics


Information Hiding
Information

hiding

Specific to both structured design and OOD In OOD the concept is close related to abstraction, encapsulation and modularity
OO

information hiding

Each class should hide (keep secret) its design or construction decisions from all other classes Class design decision
What is public and what is secret

Examples

24

Main software construction heuristics


Identify areas likely to change
Anticipate

and accommodate

changes
attribute of a good program design
Isolate

unstable areas

25

Main software construction heuristics


Keep coupling loose
Coupling

shows how tightly a class or routine is related to other classes or routines


The goal is loose coupling

Types

of coupling

Simple data parameter coupling Simple object coupling Object-parameter coupling Semantic coupling (dangerous)

26

Main software construction heuristics


Cohesion
Relates to

the module internal construction A cohesive module (component) performs a single task with very few interactions with routines of other modules Types of cohesion (from high cohesion to low cohesion)
functional (desirable) sequential communicational procedural temporary logical coincidental (non desirable)

27

Main software construction heuristics


Other heuristics
Look

for common design patterns Design for test Choose carefully binding time Draw diagrams Keep the design modular

28

Design Practices
Iterate Divide

et Impera

Top Down approach Bottom Up approach


Prototyping Collaborative

Design

29

Design Practices
Divide et Impera - Top Down (Procedural Development)

Problem domain Abstraction Module Stub

Stub

Module

Module

Stub Procedural Abstraction

Proc

Proc

Proc

Proc

30

Design Practices
Divide et Impera Bottom Up (OO development)
Integration Driver

Integration Driver

Class

Driver

Integration Driver

Driver

Class

Class

Driver

Implementation ADT ... ADT Abstraction, Data Abstraction Problem domain

31

Part 2
Programming Objective

Paradigms

Presenting the main computational models and programming paradigms

32

Programming features
(Computer)

Programming

science of creating software for solving problems both knowledge intensive and labor intensive process
Problem

dimensions

simple, complex, small, large, IO intensive, algorithmic intensive, data intensive

Modern

software development tools

complex tools embedding


software construction knowledge, reuse at different levels.

Ioan Salomie - OO Programming Techniques


33

Choosing the right programming language


Difficult

problem Problem - Programming Language mapping Are there any decision metrics??

Ioan Salomie - OO Programming Techniques


34

Computational Models
Computing Model Main Abstractions
Procedural Oriented Procedures Algorithms Substitution principle Objects and classes

Object Oriented

Rule Oriented

If-then rules

Logic Oriented

Goals (using predicate calculus) Invariant relationships

Constraint Oriented

Ioan Salomie - OO Programming Techniques


35

Programming paradigms

Procedural programming
features Representative languages: Fortran, Algol 60, Cobol, Pascal, C (partial C++)

OOP
main features Simula, Smalltalk, C++, Java, C#

Concurrent programming
main features PL/I, Algol 68, Modula, Ada83, Ada95

Functional programming
main features Lisp, ML, Haskel

Logic programming:
main features Prolog

Scripting languages
main features Ruby

Ioan Salomie - OO Programming Techniques


36

Classes of algorithms and problems


Type Uniprocessor Multiprocessor Multiprogramming

Sequential Sequential Execution

Concurrent Apparent Real concurrency Concurrency

Ioan Salomie - OO Programming Techniques


37

Sequential Programming
Execution

of one statement at a time Usually executed on a single processor


Processor speed is important
Transforms

input data to results according to the implemented algorithm Usually deterministic

Ioan Salomie - OO Programming Techniques


38

Concurrent Programming
Concurrent

program

Programming entities - executed simultaneously (in parallel) Dynamically information sharing


Large

variety of concurrent models support

Apparent or real concurrency


Execution

mono, multi, parallel or distributed processors

Transform

sequential to concurrent programming


39

Ioan Salomie - OO Programming Techniques

Concurrent programming (cont.)


Concurrent

programming

Strategy to decompose large tasks into multiple smaller tasks


Smaller tasks - executed simultaneously with the others.

Assigning the smaller tasks to multiple workers to work on simultaneously. Coordinating the workers

40

Parallel programming
Special

form of concurrent programming


Multiple physical processors Memory sharing

Ioan Salomie - OO Programming Techniques


41

Parallel programming
Approaches

to constructing parallel applications:


Functional parallelism Masterslave parallelism SPMD parallelism
same code, replicated to each process

Parallel

programming main tasks

Decomposing tasks Distributing tasks Coordinating tasks

Ioan Salomie - OO Programming Techniques


42

Distributed programming
Special

form of concurrent programming


multiple physical processors remotely located no shared memory

Interprocess

communication

communication channels message exchange

Ioan Salomie - OO Programming Techniques


43

Concurrent vs. Sequential Programming


Q:

Why concurrent programming is more difficult than sequential programming? A: mainly due to management of
control flow of multiple execution threads data placement and access of global data. synchronizing events

Ioan Salomie - OO Programming Techniques


44

Classes of Algorithms / Programming by data handling


Transformational read data process data output results

programming

Based on the following sequence:

Expressed as functions of n inputs generating m outputs Program behavior depends on program current state and input Can be parallelized

Ioan Salomie - OO Programming Techniques


45

Classes of Algorithms / Programming by data handling


Reactive

programming

Interact with the environment during execution; Cannot be specified as a function Event driven programming Inherently non-deterministic

Ioan Salomie - OO Programming Techniques


46

Note
The references used for preparing these lecture notes are indicated in the Bibliography folder of the course site

47

Das könnte Ihnen auch gefallen