Programmazione. Prof. Marco Bertini

Similar documents
Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini

CHAPTER 5 GENERAL OOP CONCEPTS

Programmazione. Prof. Marco Bertini

Unit - IV CHAPTER - 13 INTRODUCTION TO OOP WITH C++ Part 1 Choose the best answer

Dr. Md. Humayun Kabir CSE Department, BUET

Object oriented programming Concepts

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Elementary Concepts of Object Class

1. Write two major differences between Object-oriented programming and procedural programming?

What is a Programming Paradigm

CSCU9T4: Managing Information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

Object-Oriented Programming. Objects. Objects. Objects

Object Model. Object Orientated Analysis and Design. Benjamin Kenwright

Review&Preview 1/23/15, 4:08:07 PM 1. 3rd edition - standardized, and standard library allows programmer to start from a higher level

Fast Introduction to Object Oriented Programming and C++

CSI33 Data Structures

MA400: Financial Mathematics

Introduction to Object-Oriented Programming

Chapter 1: Principles of Programming and Software Engineering

A STUDY OF OBJECT ORIENTED ANALYSIS AND DESIGN

CPS 506 Comparative Programming Languages. Programming Language

What are the characteristics of Object Oriented programming language?

Chapter 5 Object-Oriented Programming

Programmazione. Prof. Marco Bertini

Unit 1 : Principles of object oriented programming

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Chapter 1: Programming Principles

CS 376b Computer Vision

New Programming Paradigms

Object-Oriented Technology. Rick Mercer

Object-oriented development. Object-oriented Design. Objectives. Characteristics of OOD. Interacting objects. Topics covered

Object-Oriented Design

Object-Oriented Programming

Object Orientated Analysis and Design. Benjamin Kenwright

Design Patterns. Gunnar Gotshalks A4-1

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Programmazione. Prof. Marco Bertini

Laboratorio di Tecnologie dell'informazione

COMP322 - Introduction to C++ Lecture 01 - Introduction

Advanced Database Applications. Object Oriented Database Management Chapter 13 10/29/2016. Object DBMSs

CSC Advanced Object Oriented Programming, Spring Overview

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Software Design and Analysis for Engineers

Introduction to Object Oriented Analysis and Design

1. Software Systems Complexity, OO Paradigm, UML

Topic : Object Oriented Design Principles

Component Design. Systems Engineering BSc Course. Budapest University of Technology and Economics Department of Measurement and Information Systems

OBJECT ORIENTED PROGRAMMING

Unit Wise Questions. Unit-1 Concepts

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Object-Oriented Programming, Classes

Data Abstraction. Hwansoo Han

Laboratorio di Tecnologie dell'informazione

Object-Oriented Programming

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods

BASIC CONCEPT OF OOP

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Object Oriented Programming

Laboratorio di Tecnologie dell'informazione

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

Fundamental Concepts (Principles) of Object Oriented Programming These slides are based on:

Principles of Programming Languages, 2

OBJECT-ORIENTED MODELING AND DESIGN. Introduction

CS304 Object Oriented Programming Final Term

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

THE OBJECT-ORIENTED DESIGN PROCESS AND DESIGN AXIOMS (CH -9)

Practical Object-Oriented Design in Ruby

Object-Oriented Programming and Design

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Object Oriented Programming. Solved MCQs - Part 2

B16 Object Oriented Programming

10조 이호진 이지 호

Unit E Step-by-Step: Programming with Python

Topics in Object-Oriented Design Patterns

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

AN OVERVIEW OF C++ 1

Concepts of Programming Languages

LECTURE 3: SOFTWARE DESIGN. Software Engineering Mike Wooldridge

CSE 70 Final Exam Fall 2009

The major elements of the object-oriented model

Object Oriented Design

*ANSWERS * **********************************

COURSE 2 DESIGN PATTERNS

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

System Analysis and Design. Introduction: Object Oriented Design

The Parts of a C++ Program

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

Lecture Chapter 2 Software Development

QUIZ. What is wrong with this code that uses default arguments?

Classes, subclasses, subtyping

Polymorphism. Arizona State University 1

Cours de C++ Introduction

Responsibilities. Using several specific design principles to guide OO design decisions.

Transcription:

Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/

Introduction

Why OO Development? Improved structure of software easier to: Understand Maintain Enhance Reusable software components & modules: Enhance an existing component Make new components more generalised

Structured vs. OO approach Structured analysis and design (or structured programming) mostly focussed on procedural structure and as such, functionality relating to the same data was still often spread throughout the software system. The object oriented paradigm focuses on structuring the system around the data by encapsulating data inside objects so that all functionality relating to that data is, in theory, contained within the object itself.

3 Key OO concepts Main idea: encapsulate data inside an Object 1. Data Abstraction: data is now seen in terms of the operations that we can perform on that data and not only in terms of the pure data values. ADT s, information hiding: because the details of the data formats and how those operations are actually implemented are hidden from other code that uses an object. C++ classes: the principle facility used to implement data abstraction.

3 Key OO concepts Main idea: encapsulate data inside an Object 1. Data Abstraction: data is now seen in terms of the operations that we can perform on that data and not only in terms of the pure data values. ADT s, information hiding: because the details of Abstraction is a good engineering tool: it allows to specify the external the properties data formats of an entity and how without those having operations to specify are the internal actually details. Thus, implemented we can use are the hidden entity from without other having code to deal with that its uses implementation an object. details. Designing a complex system becomes easier, since we have to deal with C++ its different classes: the levels principle of abstraction facility without used to having to deal with implement the more data complex abstraction. details of the levels below.

3 Key OO concepts - cont. 2. Inheritance (generalisation/specialization) Class hierarchies, inheritance: some classes of objects are generalizations of other more specific classes of objects; therefore it makes sense to i) put general functionality into what we refer to as a base class and ii) to allow more specific functionality to be placed in classes derived from the base class. The derived classes are said to inherit (or extend) functionality from the base class.

3 Key OO concepts - cont. 3. Polymorphism: we can use different types of objects in the same way and the software system in this case C++, but could be Java or Python will work out for us which functionality should actually be invoked, according to the actual type of object that is involved in a particular usage. Same operations on different classes/objects: arithmetic operators that can apply to both integer and floating point numbers, although the actual implementation of arithmetic is quite different. Virtual functions Operator overloading In C++ polymorphism is supported on objects using what are called virtual functions as well as through further overloading of standard operators.

Objects and Classes An object is like an ordinary variable: is an actual instance of a software entity that holds real information, perhaps about something in the real world. Holds information. Software realization of some real world thing. Can have certain operations applied to it.

Objects and Classes A class is (like) a type: Abstraction of a set of objects that behave identically: brings together the implementation of data and operations. Defines internal implementation, operations. Can create (instantiate) objects from a class: just like for a built-in type (e.g. int or float), a user defined type using the class facility can then be instantiated into objects or variables.

Objects and Classes Classes help you to organize your code and to reason about your programs. A class is the representation of an idea, a concept, in the code. An object of a class represents a particular example of the idea in the code. Without classes, a reader of the code would have to guess about the relationships among data items and functions - classes make such relationships explicit and understood by compilers. With classes, more of the high-level structure of your program is reflected in the code, not just in the comments.

Objects and Classes

Objects and Classes Class

Objects and Classes Objects Class

Objects and Classes Class Object

Procedural Programming vs. OOP A program can be viewed as a sequence of procedure calls. The main program is responsible to pass data to the individual calls, the data is processed by the procedures. A program can be viewed as a web of interacting objects, each house-keeping its own state Object 1 data Main program data Object 3 data Procedure 1 Procedure 2 Procedure 3 Object 4 data Object 2 data

Objects without Classes JavaScript is an object-oriented language that does NOT have classes. It uses prototypes (it s called prototype-based or instance-based). The inheritance of class-based OO languages becomes behaviour reuse, through decoration of existing objects which serve as prototypes. ECMAScript 6 has introduced classes also in Javascript.

OO methods OO methods are a set of techniques for analyzing, decomposing and modularizing software systems architectures In general, systems evolve and functionality changes, but the objects (and classes of objects) tend to remain stable over time. The object oriented paradigm influences the entire software development process. It proceeds through a set of phases, although the boundaries are often blurred.

OO Software Development OO Analysis: Identifying required functionality, classes and their relationships: often uses tools drawn from the Unified Modelling Language (UML) such as class diagrams and use cases. OO Design: Specifying class hierarchies, class interfaces and class behaviour: UML tools such as class diagrams, interaction diagrams and state diagrams can be used in OO design. OO Programming: Implementing an OO design in an OO programming language: in this phase code is actually written, tested and integrated with other code.

OOA Object-oriented analysis (OOA) applies object-modeling techniques to analyze the functional requirements for a system. OOA looks at the problem domain, with the aim of producing a conceptual model of the information that exists in the area being analyzed and understanding the requirements. Analysis models do not consider any implementation constraints that might exist.

OOD Object-oriented design (OOD) elaborates the analysis models to produce implementation specifications. During OOD developers create abstractions and mechanisms necessary to meet the systems behavioral requirements determined during OOA The concepts in the analysis model are mapped onto implementation classes. The result is a model of the solution domain, a detailed description of how the system is to be built.

OOD - cont. OOD is relatively independent of the programming language used OOA focuses on what the system does, OOD on how the system does it.

Goals of design Create software that is easy to change and extend, i.e. flexible. The goal is to attain highly cohesive, loosely coupled software. Decompose the system into modules, determining relations between them, e.g. identifying dependencies and form of communications Determine the required classes, their use, their inheritance and composition relationships.

Object Oriented Programming Object-oriented programming (OOP) is primarily concerned with programming language and software implementation issues OOP is a programming paradigm that uses objects data structures consisting of data and methods together with their interactions to design applications and computer programs. An object-oriented program may be viewed as a collection of interacting objects, as opposed to the structural model, in which a program is seen as a list of tasks (subroutines) to perform.

C++ "I invented the term 'Object-Oriented', and I can tell you I did not have C++ in mind." - Alan Kay

History of C++ C++ invented by Bjarne Stroustrup, early 1980 s C++ is not just an Object-Oriented Programming Language, it s multi-paradigm First commercial release 1985 was a C preprocessor. ISO Standard in 1998 (C++98), updated in 2003 New standards: C++11, C++14 and C++17 (check your compiler)

C++ and C C++ is a direct descendant of C that retains almost all of C as a subset. C++ provides stronger type checking than C and directly supports a wider range of programming styles than C.

C++ sub-languages C++ can be considered as a federation of languages; the primary sublanguages are: C: since C++ supports every programming technique supported by C (e.g. Procedural) Object Oriented C++: with classes, encapsulation, inheritance, polymorphism, etc. Generic Programming C++: C++ templates Functional: C++11 has introduced lambdas

The first C++ program

Makefiles Larger (real world) projects will require to use a Makefile. A makefile is a text file (that is referenced by the make command) that describes the building of targets (executables and libraries), and contains information such as source-level dependencies and build-order dependencies. Eclipse is an IDE that handles these makefiles

Creating Makefiles Makefiles can be created from other programs that tell how to create them. E.g. CMake is a program that creates makefiles that in turn tell how to create a program. CLion is an IDE that is based on CMake.

The C++ Hello world #include <iostream> int main() { } // let s greet std::cout << "Hello, "; std::string name = "world"; std::cout << name << std::endl; To compile: g++ -Wall o hello hello.cpp

Reading material L.J. Aguilar, Fondamenti di programmazione in C++. Algoritmi, strutture dati e oggetti - cap. 1 D.S. Malik, "Programmazione in C++ - cap. 1 Thinking in C++, 2nd ed. Volume 1, cap. 1 pp. 23-30

Credits These slides are (heavily) based on the material of Dr. Ian Richards, CSC2402, Univ. of Southern Queensland Dr. Douglas C. Schmidt, Washington University, St. Louis