Object Oriented Software Design - Introduction

14
Object Oriented Software Design Introduction Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant’Anna – Pisa September 23, 2010 G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 1 / 32 Outline 1 Summary of the course 2 Introduction 3 Learning to program 4 The human factor 5 How to become a master G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 2 / 32

Transcript of Object Oriented Software Design - Introduction

Page 1: Object Oriented Software Design - Introduction

Object Oriented Software DesignIntroduction

Giuseppe Liparihttp://retis.sssup.it/~lipari

Scuola Superiore Sant’Anna – Pisa

September 23, 2010

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 1 / 32

Outline

1 Summary of the course

2 Introduction

3 Learning to program

4 The human factor

5 How to become a master

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 2 / 32

Page 2: Object Oriented Software Design - Introduction

Organization of the course

The course is divided into 2 semesters, each one entitles to 6 credits

The first semester is open to students of:GPISTIMCNEMAPNET

The second semester is open to students of:GPISTAllievi of Scuola Sant’Anna

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 4 / 32

First semester

First semesterObjective: to acquire basics knowledge of object oriented designand programmingAbstract Data TypesProgramming in Java and in C++In both languages:

Inheritance, vs. composition, when and when not?Exception safetyDesign for re-useTesting while programmingGenerics

Exam:3 assignments: 2 small programs, plus one bigger to bedeveloped during the course and handed over at the endFor MAPNET and IMCNE only: an oral examination

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 5 / 32

Page 3: Object Oriented Software Design - Introduction

Second semester

Design PatternsHow to reuse existing knowledge

Software EngineeringRequirement AnalysisClassical Software life cyclesAgile and Xtreme programming

ToolsThe Boost libraryCVS, SVN, (git?)Tools for testingDocumentation

Concurrent ProgrammingThe Boost thread libraryDistributed MiddlewareDesign Patterns for Distributed Concurrent Programming

Exam:A project and oral examination.

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 6 / 32

Books and material

Java ProgrammingBruce Eckel’s “Thinking in Java”Sun’s documentation and Tutorials

C++ ProgrammingStroustup’s “C++ Language” (Language reference)Bruce Eckel’s “Thinking in C++”, Volume 1 (Learning C++)Herb Sutter’s “Exceptional C++” (Advanced Tips and Tricks)Alexandrescu’s “Modern C++ programming” (Meta-programmingwith Templates)

And of course, these slides, and various material to be found over theInternet

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 7 / 32

Page 4: Object Oriented Software Design - Introduction

Something to think about

“Computer science is no more about computers than astronomy isabout telescopes”

– Edsger Dijkstra

What else might it be about?

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 9 / 32

Algorithms, programs, processes

Algorithm:It is a logical procedure thought to solve a certain problemIt is informally specified as a sequence of elementary steps that anexecution machine must follow to solve the problemit is not necessarily expressed in a formal programming language!

Program:It is the implementation of an algorithm in a programming language,that can be executed by an autonomous machine (calculator)It can be executed several times, every time with different inputs

Process:An instance of a program that, given a set of input values, producesa set of outputs

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 10 / 32

Page 5: Object Oriented Software Design - Introduction

Algorithm

Given a computational problem, it isnecessary to find a procedure,consisting of a finite set of simplesteps that will produce the solution ofthe problem.Such a procedure is called“Algorithm” in honor of arabmathematician Mohammed ibn-Musaal-Khuwarizmi (VIII century AC)

Figure: al-Khuwarizmi

Examples:How to prepare a coffeHow to buy a coffe from the vending machineHow to calculate the square root of a number

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 11 / 32

Calculators

An algorithm needs a machine to execute itMachine here is intended in the abstract sense

It can even be a human being, or group of peopleHowever, it is important that the algorithm it is described so that themachine can execute it without further instructions, or wronginterpretation of what to doTherefore, the steps must be simple, and precisely described

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 12 / 32

Page 6: Object Oriented Software Design - Introduction

Coffe time!

Example: in the description of thealgorithm to prepare a coffe:

we must specify how much coffe to put,so that the machine cannot be wrong inpreparing itIf the machine is a calculator (a stupidmachine!), then we must tell it exactlyhow much coffe to putIf the machine is smart, we can be lessprecise, for example, put “coffee” untilthe machine is full(actually, many human beings not notsmart enough to prepare a coffe!)

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 13 / 32

Programs

In this course, we are interested indescribing an algorithm so that acomputer can understand andexecute itHow to communicate with acomputer?

We need to use a language that the computer can understand

A programming language is not so much different than any humanlanguageThe main difference is that the interpretation of a sentenceexpressed in a programming language must be unambiguous

Human languages, instead, allow plenty of ambiguities!

Therefore, a programming language is grounded on a solidmathematical basis

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 14 / 32

Page 7: Object Oriented Software Design - Introduction

Human beings . . . are very much at the mercy of the particularlanguage which has become the medium of expression fortheir society. It is quite an illusion to imagine that one adjuststo reality essentially without the use of language and thatlanguage is merely an incidental means of solving specificproblems of communication and reflection. The fact of thematter is that the “real world” is to a large extentunconsciously built up on the language habits of the group.

The Status Of Linguistics As A Science, 1929, Edward Sapir

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 16 / 32

Learning a programming language

Learning a programming language is not so different from learninga natural language

First of all, it is important to point outthat the structure of the languageinfluences the way we think atproblems

It is well known that people fromdifferent countries tend to think indifferent waysNatural language is the primarymental knowledge representationsystem a

Therefore, reasoning is heavilyinfluenced by language

aSee

http://en.wikipedia.org/wiki/Cognitive_psychology. Imagetaken from “Myth, Ritual, and Symbolism” http://bit.ly/cLLmgc

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 17 / 32

Page 8: Object Oriented Software Design - Introduction

Natural language

To be fluent in another language (e.g. English), it is important tothink sentences in that language

Thinking a sentence in the mother-toungue (e.g. Italian) and thenmentally translate to the new language (e.g. English) oftenproduces unnatural sentencesWhen speaking in a new language, we should also “switch” to anew way of thinking1

1Image taken from “Natural Language and the Computer Representation of Knowledge” http://bit.ly/ccdzLh

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 18 / 32

Language structure

Back to programming languages

A low level language (MS Visual Basic, C,etc.) lacks strong structure

Emphasis on programs as collection offunctions acting on global and local dataCorrespondingly, low-level programs madeby beginners tend to lack in structureWhen they have, it is difficult to find andunderstand it

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 19 / 32

Page 9: Object Oriented Software Design - Introduction

Object Oriented Language Structure

Object-oriented programminglanguages favor a structure

Emphasis on programs asset of objectscommunicating throughwell-defined interfacesEverything is an object!

The programmers has tomodel the world as a set ofobject

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 20 / 32

Functional programming

Functional programming2

Functional languages impose yet anotherstructure

Emphasis on functions as first-classconceptsProgams manipulate functions as wellas data

2Comic strip from http://xkcd.com

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 21 / 32

Page 10: Object Oriented Software Design - Introduction

Learning the basics

Where to start from?

Similarly to learning natural languages, you should start fromlearning to read and understand programs written by othersTo understand: you should try to mentally execute the code, justas a computer would do

To be able to do this, you have to understand first how the “abstractmachine” executes each part of the programIf you learn how to do this, you will not need sophisticateddebuggers

Then, you can learn to write code, keeping in mind how it isexecuted by the machine

That’s the most difficult thing to do, because at the beginning youhaven’t the “right structure” in your mind yet

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 22 / 32

Human interaction

Computer programming has important social aspectsAt the beginning you learn to write small programs all by yourself

It’s you and the PCthe teacher gives you an exercise, you have to transform thespecification into a programOr, you want to write a program for yourself, so you also give thespecification

When you code in this way, you have complete control of all theaspects

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 24 / 32

Page 11: Object Oriented Software Design - Introduction

Large programs

However, when you become a professional programmer, it’s acompletely different story

Professional programs get larger and larger (tens of thousands oflines of code), and it takes much longer to write themEven if you are the only programmer, you often lose control of whatyou have done the week before (what was the meaning of that kvariable?)Most often, however, the program code is written by a teamDepending on the project, the team can consist also of 5-6programmers, and there can be many teams working on differentparts of the same projectIt is important to learn how to work in a group

Therefore, it is important to be able to communicate betweenpartners without misunderstandingsThe team leadership is a key factor for the success of the project

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 25 / 32

Specification

How to communicate with customers?A professional team writes programs for someone else (thecustomer)So, the customers must tell then team exactly what they wantThat’s the specification

Still done in natural languageA very difficult aspect

Most of the failures in completing/delivering a corrects softwareproject are caused by

Wrong or ambiguous initial specificationWrong interpretation of the specificationContinuously changing specification after the design

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 26 / 32

Page 12: Object Oriented Software Design - Introduction

Software engineering

Software engineering is also a social scienceTeam managementProject planningRisk managementDealing with the customerContinuosly evolving specification

All these aspects are as important as learning how to program

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 27 / 32

How to become a good software designer

How to become a software design master?Engineering approachLot of experience

Learning to develop good software is similar to learning to playgood chess

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 29 / 32

Page 13: Object Oriented Software Design - Introduction

How to become a chess master

First, learn the rulese.g., names of pieces, legal movements,captures, board geometry, etc.

Second, learn the principlese.g., relative value of certain pieces, power of athreat, etc.But principles are abstract. How to apply themin practice?

Third, learn the patterns by studying games ofother masters

These games have certain patterns that mustbe understood, memorized, and appliedrepeatedly until they become second nature.

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 30 / 32

To become a software design master

First, learn the rulese.g., programming languages, data structures, etc.

Second, learn the principlese.g., software engineering principles such as separation ofconcerns, etc.But principles are abstract. How to apply them in practice?

Third, learn the patterns by studying designs of other mastersThese designs have certain patterns that must be understood,memorized, and applied repeatedly until they become secondnature.

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 31 / 32

Page 14: Object Oriented Software Design - Introduction

This course

This course is a tentative to form “Software Design Masters” in ObjectOriented software technology

A bottom-up approachObject Oriented LanguagesProgramming TechniquesDesign TechniquesAn introduction to Software Engineering principles and tools

This course has been designed to be interactiveI need your help to carry on until the end!

G. Lipari (Scuola Superiore Sant’Anna) OOSD September 23, 2010 32 / 32