This presentation talks about behavioural design patterns. In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication. In particular in the slides are described the following patterns:
- Command
- Iterator
- Observer
- Strategy
- Template Method
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about creational design patterns. In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. In particular in the slides are described the following patterns:
- Singleton
- Builder
- Abstract Factory
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about dependecy injection, an architectural design pattern that aims to help developer to resolve dependencies between objects. Starting by describing general problem of dependecy resolution, the presentation continues presenting Inversion of Control (IoC) pattern, constructor injection and setting injection. As examples, some frameworks and libraries are reported, such as:
- Google Guice
- Spring framework
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about structural design patterns. In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. In particular in the slides are described the following patterns:
- Decorator
- Proxy
- Facade
- Adapter
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML class diagrams. The slides contain information about how to use sequence diagrams to represent components' interactions in a software system. UML 2.x featuers are also described, like frames.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML use cases and use cases diagrams. The slides contain information about what is a scenario, an actor, an use case and interactions between them.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
A very introductive presentation about how Model-View-Controller pattern (MVC) and Dependence Injection (DI) are implemented in some popular frameworks, such as Spring and Angular JS.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Il Corso Programmazione Java Base di K-Tech (http://www.k-tech.it) ha come obiettivo quello di far comprendere le tecniche di programmazione orientata agli oggetti, cioè di modellare e “pensare” a oggetti, di trasmettere i concetti base del linguaggio e le basi per sviluppare piccole applicazioni in modo autonomo.
Il corso Programmazione Java Base è composto da dodici moduli:
1. Introduzione
2. Ciclo di sviluppo
3. Sintassi Elementare
4. Principi OOP
5. Classi e Oggetti
6. Concetti Object Oriented
7. Collections
8. Eccezioni
9. Input Output
10. Serialization
11. Unit Testing
12. Threads
Leggi il programma completo: http://www.k-tech.it/formazione/catalogo/programmazione_java_base
This presentation talks about creational design patterns. In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. In particular in the slides are described the following patterns:
- Singleton
- Builder
- Abstract Factory
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about dependecy injection, an architectural design pattern that aims to help developer to resolve dependencies between objects. Starting by describing general problem of dependecy resolution, the presentation continues presenting Inversion of Control (IoC) pattern, constructor injection and setting injection. As examples, some frameworks and libraries are reported, such as:
- Google Guice
- Spring framework
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about structural design patterns. In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. In particular in the slides are described the following patterns:
- Decorator
- Proxy
- Facade
- Adapter
Design patterns are presented using examples in Java, Scala and Javascript.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML class diagrams. The slides contain information about how to use sequence diagrams to represent components' interactions in a software system. UML 2.x featuers are also described, like frames.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML use cases and use cases diagrams. The slides contain information about what is a scenario, an actor, an use case and interactions between them.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
A very introductive presentation about how Model-View-Controller pattern (MVC) and Dependence Injection (DI) are implemented in some popular frameworks, such as Spring and Angular JS.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Il Corso Programmazione Java Base di K-Tech (http://www.k-tech.it) ha come obiettivo quello di far comprendere le tecniche di programmazione orientata agli oggetti, cioè di modellare e “pensare” a oggetti, di trasmettere i concetti base del linguaggio e le basi per sviluppare piccole applicazioni in modo autonomo.
Il corso Programmazione Java Base è composto da dodici moduli:
1. Introduzione
2. Ciclo di sviluppo
3. Sintassi Elementare
4. Principi OOP
5. Classi e Oggetti
6. Concetti Object Oriented
7. Collections
8. Eccezioni
9. Input Output
10. Serialization
11. Unit Testing
12. Threads
Leggi il programma completo: http://www.k-tech.it/formazione/catalogo/programmazione_java_base
A very introductive presentation about reactive programming principles. Starting from synchronous standard programming, I try to present the needs that driven to reactive programming. Callbacks, Future, Promises, Observables and Actor model are the main issues. I also make an introduction to the Reactive Manifesto.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Slide introduttive al linguaggio Java 8 in preparazione alla certificazione OCA 1Z0-808.
Lezione del 12-10-2017 tenuta da Valerio Radice presso Nextre Engeneering
https://www.nextre.it/corso/corso-java-oca/
Very little workshop on HLS:
Mention of Synthesizing hardware using high level language, in particular C-like languages. Analysis of existent old language since 1980 to 2000: Cones, HardwareC, Transmogrifier C, SystemC, C2Verilog, Handel-C. Open problems using C-like languages (taken from Stephen Edwards' "The challenges of synthesizing Hardware from C-like languages").
Hardware design and synthesis using Esterel, reactive and synchronous language, ideal to describe a *behavioural* structure of hardware concurrent real-time controller and to test formal correctness. Easiness in creation of VHDL, Verilog, SystemC, Finite State Automata, dataflow design, and implementation on ASIC or FPGA or RePIC (processor architecture supporting direct esterel execution).
Example of a Preudo-Random Bit Sequence using Esterel versus the implementation using OrCAD software
Slide quarta lezione al linguaggio Java 8 in preparazione alla certificazione OCA 1Z0-808.
Argomenti:
Design Pattern: Singleton
Classe Astratta
Interfaccia e interfaccia funzionale
Ereditarietà e costruttori
Super e this
Incapsulamento
Polimorfismo
Varargs
Overload e Override
Invocazione virtuale dei metodi
Lezione del 28-11-2017 tenuta da Valerio Radice presso Nextre Engeneering
https://www.nextre.it/corso/corso-java-oca/
This presentation talks about the main features of UML class diagrams. The slides contain information about how to represent a class, what is a classe feature, what are possible association types, class dependency, hineritance and subtyping.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the first part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Thread safety
- Types of race conditions
- Locking (reentrant locks, intrinsic locks, synchronized blocks)
- Locking pitfalls
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This document discusses Java input/output (I/O) streams and readers/writers for processing files, URLs, and other sources of input and output. It covers obtaining and working with input and output streams, reading and writing bytes, character encodings, text I/O, random access files, file operations, URL connections, and object serialization. The key classes for I/O include InputStream, OutputStream, Reader, Writer, File, Path, and URLConnection.
This presentation introduces basic concepts about the Java socket abstraction. These slides introduce the following concepts:
- What is a socket
- How to implement a client program
- How to implement a server program
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the second part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Conditional locking
- Volatile variables
- Thread confinement
- Immutability
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
A brief introduction to UML: the history, what are the problems that UML tries to resolve and how we should use it during software design and development.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some advanced concepts of threads, as implemented in the Java platform. It is part of a series of slides dedicated to threads. This slides introduces the following concepts:
- Callable
- Futures
- Executors and executor services
- Deadlocks (brief introduction)
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
A very introductive presentation about reactive programming principles. Starting from synchronous standard programming, I try to present the needs that driven to reactive programming. Callbacks, Future, Promises, Observables and Actor model are the main issues. I also make an introduction to the Reactive Manifesto.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Slide introduttive al linguaggio Java 8 in preparazione alla certificazione OCA 1Z0-808.
Lezione del 12-10-2017 tenuta da Valerio Radice presso Nextre Engeneering
https://www.nextre.it/corso/corso-java-oca/
Very little workshop on HLS:
Mention of Synthesizing hardware using high level language, in particular C-like languages. Analysis of existent old language since 1980 to 2000: Cones, HardwareC, Transmogrifier C, SystemC, C2Verilog, Handel-C. Open problems using C-like languages (taken from Stephen Edwards' "The challenges of synthesizing Hardware from C-like languages").
Hardware design and synthesis using Esterel, reactive and synchronous language, ideal to describe a *behavioural* structure of hardware concurrent real-time controller and to test formal correctness. Easiness in creation of VHDL, Verilog, SystemC, Finite State Automata, dataflow design, and implementation on ASIC or FPGA or RePIC (processor architecture supporting direct esterel execution).
Example of a Preudo-Random Bit Sequence using Esterel versus the implementation using OrCAD software
Slide quarta lezione al linguaggio Java 8 in preparazione alla certificazione OCA 1Z0-808.
Argomenti:
Design Pattern: Singleton
Classe Astratta
Interfaccia e interfaccia funzionale
Ereditarietà e costruttori
Super e this
Incapsulamento
Polimorfismo
Varargs
Overload e Override
Invocazione virtuale dei metodi
Lezione del 28-11-2017 tenuta da Valerio Radice presso Nextre Engeneering
https://www.nextre.it/corso/corso-java-oca/
This presentation talks about the main features of UML class diagrams. The slides contain information about how to represent a class, what is a classe feature, what are possible association types, class dependency, hineritance and subtyping.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the first part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Thread safety
- Types of race conditions
- Locking (reentrant locks, intrinsic locks, synchronized blocks)
- Locking pitfalls
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This document discusses Java input/output (I/O) streams and readers/writers for processing files, URLs, and other sources of input and output. It covers obtaining and working with input and output streams, reading and writing bytes, character encodings, text I/O, random access files, file operations, URL connections, and object serialization. The key classes for I/O include InputStream, OutputStream, Reader, Writer, File, Path, and URLConnection.
This presentation introduces basic concepts about the Java socket abstraction. These slides introduce the following concepts:
- What is a socket
- How to implement a client program
- How to implement a server program
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the concept of synchronization beatween threads, as implemented in the Java platform. It is the second part of a series of slides dedicated to thread synchronization. This slides introduces the following concepts:
- Conditional locking
- Volatile variables
- Thread confinement
- Immutability
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
A brief introduction to UML: the history, what are the problems that UML tries to resolve and how we should use it during software design and development.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some advanced concepts of threads, as implemented in the Java platform. It is part of a series of slides dedicated to threads. This slides introduces the following concepts:
- Callable
- Futures
- Executors and executor services
- Deadlocks (brief introduction)
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the Java concept of thread. It is the first part of a series of slides dedicated to concurrent programming. This slides introduces some basics concepts, such as:
- Differences between processes and threads
- Thread's basics
- Thread's states
- Introduction to UML sequence diagrams
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the main features of UML activity diagrams. The slides contain information about which are the main components of activity diagrams, how to use them to represent business processes and software algorithms.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Errori comuni nei documenti di Analisi dei RequisitiRiccardo Cardin
This presentation talks about common errors that I found in my career in documents of specification of requirements. In the presentation are described common errors on use cases, use cases' diagrams and on requirements' specification.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about some commonly used software architecture patterns. The main features of the following architectural patterns are described:
- Layered architecture
- Event-driven architecture (both mediator and broker topology)
- Microservices architecture (API-REST based, REST based, Centralized message topology)
Each pattern is analyzed in terms of:
- Overall agility
- Ease of deployment
- Testability
- Performance
- Scalability
- Ease of develpment.
The slide refers to the online book "Software Architecture Patterns", Mark Richards, 2015, O’Reilly.
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the main features of Swing, an UI development library for the Java ecosystem. The main focus of the slides is to show the basic features of Swing, such as:
- Main components (JFrame, JPanel, ...)
- Layout management (FlowLayout, BorderLayout, GridLayout, ...)
- Event handling
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
Java Exception Handling, Assertions and LoggingRiccardo Cardin
This presentation introduces the java exception handling mechanisms. In detail, the main focus of the slides is to show how the language implements its exception handling polices, such as:
- Checked and uncheked exception
- Try / catch blocks
- Assertions
- Logging
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces basic concepts about the Java Remote Method Invocation, a.k.a. RMI. These slides introduce the following concepts:
- Remote interfaces
- Dynamic code loading
- Serialization
- Security manager
- Exporting remote objects
- Compiling and running RMI programs
- Distributed garbage collection
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
Design pattern architetturali Model View Controller, MVP e MVVMRiccardo Cardin
This presentation talks about model view controller, model view presenter and model view viewmodel patterns. These are architectural design patterns for implementing user interfaces. They divide a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user. Also, they promote separation of concerns. As examples, some frameworks are reported, such as:
- Spring MVC
- BackboneJS
- AngularJS
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation talks about the five SOLID principles of Object Oriented Design described by Rober C. Martin in his best-seller book "Agile Principles, Patterns, and Practices in C#". The five principle described are:
- Single Responsibility Principle
- Open-Close Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces some concepts about the Java Collection framework. These slides introduce the following concepts:
- Collections and iterators
- Linked list and array list
- Hash set and tree set
- Maps
- The collection framework
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
A Matter of Plain Reason: Why Christians Must Believe in Joseph SmithRonald Kimmons
They say: "You believe in a different Jesus."
I say: "It is wonderful that you believe in Jesus. Since you do, you have to believe in living prophets, as prophetic guidance is an essential aspect of Christianity. And no one in modern times has a stronger case for being such a prophet than Joseph Smith."
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftStefano Benedetti
Il pattern architetturale MVC (Model View Controller) favorisce la manutenzione delle applicazioni web tramite una architettura elegante ed una chiara ed esplicita separazione delle competenze, l'impiego dei più diffusi pattern di software engineering, il controllo completo dell'HTML generato e degli URL, la testabilità ed estendibilità.
In questa sessione vedremo le novità principali di Asp.Net MVC in versione 3.
La sessione è stata tenuta a SMAU Business Bologna il 9 giugno 2011
SIGNALR TO-THE-MAX: VERSO IL WEB ED OLTRE!DotNetCampus
Vedremo come impiegare SignalR al massimo per realizzare una infrastruttura che serva a semplificare la creazione di HubHost da poter usare sia in modo tradizionale sia à-la WCF Service da sfruttare anche al di fuori dell'ambiente web per la comunicazione tra processi, approfondendo inoltre anche i meccanismi della Pipeline dell ErrorHandling per implementare Listener e Logger. Aggireremo inoltre una limitazione dell HubClient creandone una versione strong-typed completamente event-based.
This presentation introduces the concept of design pattern in object oriented programming and design. The slides contain information about what a design pattern is, why should we use design pattern and how design patterns could be grouped togheter. The ideas presented in the slides are taken directly from GoF's book "Design Patterns".
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Nell'ultimo quinquennio un nuovo attore si è affacciato sulla scena dell'Information Technology, il suo nome è Docker. Con una crescita esponenziale ed una diffusione ancor più rapida, Docker ha trasformato il modo di percepire e utilizzare l'ICT. Una trasformazione così radicale ed estesa da non poter ignorare la domanda: Cos'è Docker?
Lo scopo di questa giornata è di fornire una risposta a questo interrogativo, mostrando ai partecipanti nuovi scenari, per le realtà dell'Università e della Ricerca, grazie alle possibilità che Docker offre.
Latini Giuliano li guiderà lungo un percorso articolato secondo questi temi:
- Infrastruttura, Isolamento, Idempotenza e DevOps ovvero i vantaggi e i vincoli della definizione formale di un'infrastruttura, concetti teorici e glossario;
- Docker, un facilitatore per utilizzare i Container e le tecnologie ad essi collegate;
- Container vs Hypervisor, le due facce della stessa medaglia: pro, contro ed esempi d'uso;
- Dalla Vm alla Infrastruttura di Servizi, un modo per rimescolare le carte a nostro vantaggio;
- Sviluppo software: esempio d'uso di Docker nello sviluppo di una procedura PHP;
- Gestione di Sistemi: esempio di un'infrastruttura Wordpress organizzata a servizi, definizione formale implementata con Docker;
- Docker Swarm la clusterizzazione ed alta affidabilità, come il sistema risponde e si adatta alle sollecitazioni esterne in un sistema di calcolo;
L'obiettivo finale è fornire ai partecipanti un gruppo di concetti ed esempi grazie ai quali poter approfondire autonomamente Docker, personalizzandone l'uso per le proprie necessità; in alternativa ad una trattazione dettagliata ed esaustiva di tutti i temi illustrati, impossibile nel tempo a disposizione.
A conclusione del corso verrano messi a disposizione, come materiale didattico da approfondire: slide, esempi e bibliografia di riferimento.
Panoramica su Dagger2 e i suoi componenti.
Presentazione utilizzata durante il codelab "Sviluppare un'app Android utilizzando il pattern MVP, Dagger2 e RxJava" tenuto in occasione della conferenza GDG Bari Devfest 2016 presso il Politecnico di Bari.
CQRS, ovvero: 2 stack, uno per "leggere" e l'altro per "scrivere". Se per "scrivere" abbiamo l'imbarazzo della scelta (Domain Model, Command, Event Sourcing, ...) per leggere, invece, apparentemente c'è poco da dire. "Apparentemente", appunto. Parliamone :-)
1. DESIGN PATTERN COMPORTAMENTALI
INGEGNERIA DEL SOFTWARE
Università degli Studi di Padova
Dipartimento di Matematica
Corso di Laurea in Informatica, A.A. 2014 – 2015
rcardin@math.unipd.it
2. Ingegneria del software mod. A
INTRODUZIONE
2Riccardo Cardin
Architetturali
Model view controller
3. Ingegneria del software mod. A
INTRODUZIONE
Scopo dei design pattern comportamentali
In che modo un oggetto svolge la sua funzione?
In che modo diversi oggetti collaborano tra loro?
3Riccardo Cardin
4. Ingegneria del software mod. A
COMMAND
Scopo
Incapsulare una richiesta in un oggetto, cosicché i
client sia indipendenti dalle richieste
Motivazione
Necessità di gestire richieste di cui non si conoscono i
particolari
Toolkit associano ai propri elementi, richieste da eseguire
Una classe astratta, Command, definisce l’interfaccia
per eseguire la richiesta
La richiesta è un semplice oggetto
4Riccardo Cardin
5. Ingegneria del software mod. A
COMMAND
Applicabilità
Parametrizzazione di oggetti sull’azione da eseguire
Callback function
Specificare, accodare ed eseguire richieste molteplici
volte
Supporto ad operazione di Undo e Redo
Supporto a transazione
Un comando equivale ad una operazione atomica
5Riccardo Cardin
6. Ingegneria del software mod. A
COMMAND
Struttura
6Riccardo Cardin
Interfaccia di esecuzione
delle richieste
Implementa la
richiesta
concreta,
invocando
l’operazione
sul receiver
Esegue il comando
Conosce come portare a
termine la richiesta del
comando concreto
8. Ingegneria del software mod. A
COMMAND
Conseguenze
Accoppiamento “lasco” tra oggetto invocante e
quello che porta a termine l’operazione
I command possono essere estesi
I comandi possono essere composti e innestati
È facile aggiungere nuovi comandi
Le classi esistenti non devono essere modificate
8Riccardo Cardin
9. Ingegneria del software mod. A
COMMAND
Esempio
9Riccardo Cardin
Esempio
Una classe Account modella conti correnti. Le funzionalità che si
vogliono realizzare sono:
- Prelievo
- Versamento
- Undo
Questa operazione consente di annullare una delle precedenti, ma con
il vincolo che l’annullamento deve avvenire con ordine cronologico
inverso.
11. Ingegneria del software mod. A
COMMAND
Esempio
Scala: first order function
11Riccardo Cardin
object Invoker {
private var history: Seq[() => Unit] = Seq.empty
def invoke(command: => Unit) { // by-name parameter
command
history :+= command _
}
}
Invoker.invoke(println("foo"))
Invoker.invoke {
println("bar 1")
println("bar 2")
}
È possibile sostituire il command
con oggetti funzione: maggior
concisione, ma minor
configurabilità
Parametro by-name
12. Ingegneria del software mod. A
COMMAND
Esempio
Javascript: utilizzo oggetti funzione e apply
12Riccardo Cardin
(function(){
var CarManager = {
// request information
requestInfo: function( model, id ) { /* ... */ },
// purchase the car
buyVehicle: function( model, id ) { /* ... */ },
// arrange a viewing
arrangeViewing: function( model, id ){ /* ... */ }
};
})();
CarManager.execute = function ( name ) {
return CarManager[name] && CarManager[name].apply( CarManager,
[].slice.call(arguments, 1) );
};
CarManager.execute( "buyVehicle", "Ford Escort", "453543" );
Rende uniforme l’API,
utilizzando il metodo
apply
Trasforma l’oggetto
arguments in un array
13. Ingegneria del software mod. A
COMMAND
Implementazione
Quanto deve essere intelligente un comando?
Semplice binding fra il receiver e l’azione da eseguire
Comandi agnostici, autoconsistenti
Supporto all’undo e redo
Attenti allo stato del sistema da mantenere (receiver,
argomenti, valori originali del sistema …)
History list
Accumulo di errori durante l’esecuzione di più
comandi successivi
Utilizzo dei template C++ o dei Generics Java
13Riccardo Cardin
14. Ingegneria del software mod. A
ITERATOR
Scopo
Fornisce l’accesso sequenziale agli elementi di un
aggregato
Senza esporre l’implementazione dell’aggregato
Motivazione
“Per scorrere non è necessario conoscere”
Devono essere disponibili diverse politiche di
attraversamento
Iterator pattern sposta la responsabilità di
attraversamento in un oggetto iteratore
Tiene traccia dell’elemento corrente
14Riccardo Cardin
15. Ingegneria del software mod. A
ITERATOR
Applicabilità
Accedere il contenuto di un aggregato senza esporre
la rappresentazione interna
Supportare diverse politiche di attraversamento
Fornire un’interfaccia unica di attraversamento su
diversi aggregati
Polymorphic iteration
15Riccardo Cardin
16. Ingegneria del software mod. A
ITERATOR
Struttura
16Riccardo Cardin
Interfaccia per accedere e
attraversare gli aggregati
Tiene traccia della posizione
corrente nell’attraversamento
dell’aggregato
Interfaccia di creazione
degli iteratori (factory
method) Ritorna un’istanza di
un iteratore concreto
17. Ingegneria del software mod. A
ITERATOR
Conseguenze
Supporto a variazioni nelle politiche di
attraversamento di un aggregato
Semplificazione dell’interfaccia dell’aggregato
Attraversamento contemporaneo di più iteratori sul
medesimo aggregato
17Riccardo Cardin
18. Ingegneria del software mod. A
ITERATOR
Esempio
18Riccardo Cardin
Esempio
Vediamo alcuni esempi di implementazione del pattern nella libreria
J2SE di Java
19. Ingegneria del software mod. A
ITERATOR
Esempio
19Riccardo Cardin
// preparo ed eseguo una query con JDBC
String sql = “select * from utenti where user = ?”;
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1,x);
ResultSet rs = pst.executeQuery();
// ciclo i risultati con un generico iteratore
while(rs.next()) {
Utente utente = new Utente();
utente.setUser(rs.getString(“user”));
utente.setPassword(rs.getString(“password”));
// ...
}
// creo un aggregatore concreto
List<Employee> lista = new ArrayList<Employee>();
lista.add(new Employee(…));
lista.add(new Employee(…));
// ciclo tramite un generico iteratore
Iterator iterator = lista.iterator();
while(iterator.hasNext()) {
Employee e = iterator.next();
System.out.print(e.getNome() + " guadagna ");
System.out.println(e.getSalario());
}
java.util.Iterator
java.sql.ResultSet
20. Ingegneria del software mod. A
ITERATOR
Implementazione
Chi controlla l’iterazione?
External (active) iterator: il client controlla l’iterazione
Internal (passive) iterator: l’iteratore controlla l’iterazione
Chi definisce l’algoritmo di attraversamento?
Aggregato: iteratore viene definito “cursore”
Il client invoca Next sull’aggregato, fornendo il cursore
Iteratore: viene violata l’encapsulation dell’aggregato
Miglior riuso degli algoritmi di attraversamento
Iteratori robusti
Assicurarsi che l’inserimento e la cancellazione di elementi
dall’aggregato non creino interferenze
20Riccardo Cardin
21. Ingegneria del software mod. A
ITERATOR
Implementazione
Operazioni aggiuntive
Polymorphic iterator
Utilizzo del Proxy Pattern per deallocazione dell’iteratore
Accoppiamento stretto tra iteratore e aggregato
C++, dichiarare friend l’iteratore
Null Iterator
Iteratore degenere che implementa IsDone con il ritorno di
true
Utile per scorrere strutture ricorsive
21Riccardo Cardin
22. Ingegneria del software mod. A
OBSERVER
Scopo
Definisce una dipendenza “1..n” fra oggetti,
riflettendo la modifica di un oggetto sui dipendenti
Motivazione
Mantenere la consistenza fra oggetti
Modello e viste ad esso collegate
Observer pattern definisce come implementare la
relazione di dipendenza
Subject: effettua le notifiche
Observer: si aggiorna in risposta ad una notifica
“Publish - Subscribe”
22Riccardo Cardin
24. Ingegneria del software mod. A
OBSERVER
Applicabilità
Associare più “viste” differenti ad una astrazione
Aumento del grado di riuso dei singoli tipi
Il cambiamento di un oggetto richiede il
cambiamento di altri oggetti
Non si conosce quanti oggetti devono cambiare
Notificare oggetti senza fare assunzioni su quali siano
questi oggetti
Evita l’accoppiamento “forte”
24Riccardo Cardin
25. Ingegneria del software mod. A
OBSERVER
Struttura
25Riccardo Cardin
Interfaccia di
sottoscrizione,
eliminazione e notifica
Interfaccia di aggiornamento
degli oggetti che possono
essere notificati
Mantiene lo stato di
cui viene data una
“vista” concreta
Ha un riferimento al
soggetto concreto e
possiede lo stato che deve
essere aggiornato
26. Ingegneria del software mod. A
OBSERVER
Struttura
26Riccardo Cardin
Modifica e notifica
Aggiornamento delle
“viste”
27. Ingegneria del software mod. A
OBSERVER
Conseguenze
Accoppiamento “astratto” tra soggetti e osservatori
I soggetti non conoscono il tipo concreto degli osservatori
Comunicazione broadcast
Libertà di aggiungere osservatori dinamicamente
Aggiornamenti non voluti
Un operazione “innocua” sul soggetto può provocare una
cascata “pesante” di aggiornamenti
Gli osservatori non sanno cosa è cambiato nel soggetto …
27Riccardo Cardin
28. Ingegneria del software mod. A
OBSERVER
Esempio
28Riccardo Cardin
Esempio
Modifica di una o più aree di finestre in risposta alla pressione di un
pulsante (Java Swing)
29. Ingegneria del software mod. A
OBSERVER
Esempio
29Riccardo Cardin
• Il costruttore della classe JFrame possiede l’istruzione bottone.addActionListener(this)
• L’utente clicca sul pulsante e il metodo segnala viene invocato
• Il metodo segnala invoca il metodo actionPerformed su tutti gli oggetti presenti nel vettore
“ascoltatori”
30. Ingegneria del software mod. A
OBSERVER
Implementazione
Utilizzo di sistemi di lookup per gli osservatori
Nessun spreco di memoria nel soggetto
Osservare più di un soggetto alla volta
Estendere l’interfaccia di aggiornamento con il soggetto che
ha notificato
Chi deve attivare l’aggiornamento delle “viste”?
Il soggetto, dopo ogni cambiamento di stato
Il client, a termine del processo di interazione con il soggetto
Evitare puntatori “pendenti” (dangling)
Notificare solo in stati consistenti
Utilizzo del Template Method pattern
30Riccardo Cardin
31. Ingegneria del software mod. A
OBSERVER
Implementazione
Evitare protocolli di aggiornamento con assunzioni
Push model: il soggetto conosce i suoi osservatori
Pull model: il soggetto invia solo la notifica
Notifica delle modifiche sullo stato del soggetto
Gli osservatori si registrano su un particolare evento
Unificare le interfacce di soggetto e osservatore
Linguaggi che non consento l’ereditarietà multipla
Smalltalk, ad esempio …
31Riccardo Cardin
void Subject::Attach(Observer*, Aspect& interest)
void Observer::Update(Subject*, Aspect& interest)
32. Ingegneria del software mod. A
STRATEGY
Scopo
Definisce una famiglia di algoritmi, rendendoli
interscambiabili
Indipendenti dal client
Motivazione
Esistono differenti algoritmi (strategie) che non
possono essere inserite direttamente nel client
I client rischiano di divenire troppo complessi
Differenti strategie sono appropriate in casi differenti
È difficile aggiungere nuovi algoritmi e modificare gli esistenti
32Riccardo Cardin
33. Ingegneria del software mod. A
STRATEGY
Applicabilità
Diverse classi differiscono solo per il loro
comportamento
Si necessita di differenti varianti dello stesso
algoritmo
Un algoritmo utilizza dati di cui i client non devono
occuparsi
Una classe definisce differenti comportamenti,
tradotti in un serie di statement condizionali
33Riccardo Cardin
34. Ingegneria del software mod. A
STRATEGY
Struttura
34Riccardo Cardin
Interfaccia supportata da
tutti gli algoritmi
Implementazione concreta
di un algoritmo
Configurato con una
strategia concreta. Può
definire un’interfaccia per
l’accesso ai propri dati
35. Ingegneria del software mod. A
STRATEGY
Conseguenze
Definizione di famiglie di algoritmi per il riuso del
contesto
Alternativa all’ereditarietà dei client
Evita di effettuare subclassing direttamente dei contesti
Eliminazione degli statement condizionali
35Riccardo Cardin
void Composition::Repair() {
switch (_breakingStrategy) {
case SimpleStrategy:
ComposeWithSimpleCompositor();
break;
case TeXStrategy:
ComposeWithTeXCompositor();
break;
// ...
}
}
void Composition::Repair() {
_compositor->Compose();
// merge results with existing
// composition, if necessary
}
36. Ingegneria del software mod. A
STRATEGY
Conseguenze
Differenti implementazioni dello stesso
comportamento
I client a volte devono conoscere dettagli
implementativi
… per poter selezionare il corretto algoritmo …
Comunicazione tra contesto e algoritmo
Alcuni algoritmi non utilizzano tutti gli input
Incremento del numero di oggetti nell’applicazione
36Riccardo Cardin
37. Ingegneria del software mod. A
STRATEGY
Esempio
37Riccardo Cardin
Esempio
Si vuole realizzare una classe MyArray per disporre di tutte le funzioni
utili per lavorare con vettori di numeri. Si prevedono 2 funzioni di
stampa:
- Formato matematico { 67, -9, 0, 4, …}
- Formato standard Arr[0] = 67 Arr[1] = -9 Arr[2] = 0 ...
Questi formati potrebbero, in futuro, essere sostituiti o incrementati
39. Ingegneria del software mod. A
STRATEGY
Esempio
Scala: first-class functions
Le funzioni sono tipi
Possono essere assegnate a variabili
_ è una wildcard ed equivale ad un parametro differente per
ogni occorrenza
39Riccardo Cardin
type Strategy = (Int, Int) => Int
class Context(computer: Strategy) {
def use(a: Int, b: Int) { computer(a, b) }
}
val add: Strategy = _ + _
val multiply: Strategy = _ * _
new Context(multiply).use(2, 3)
Definizione di un tipo
funzione
Implementazioni
possibili Strategy
40. Ingegneria del software mod. A
STRATEGY
Implementazione
Definire le interfacce di strategie e contesti
Fornisce singolarmente i dati alle strategie
Fornire l’intero contesto alle strategie
Inserire un puntamento al contesto nelle strategie
Implementazione strategie
C++: Template, Java: Generics
Solo se l’algoritmo può essere determinato a compile time e
non può variare dinamicamente
Utilizzo strategia opzionali
Definisce una strategia di default
40Riccardo Cardin
41. Ingegneria del software mod. A
TEMPLATE METHOD
Scopo
Definisce lo scheletro di un algoritmo, lasciando
l’implementazione di alcuni passi alle sottoclassi
Nessuna modifica all’algoritmo originale
Motivazione
Definire un algoritmo in termini di operazioni astratte
Viene fissato solo l’ordine delle operazioni
Le sottoclassi forniscono il comportamento concreto
41Riccardo Cardin
42. Ingegneria del software mod. A
TEMPLATE METHOD
Applicabilità
Implementare le parti invarianti di un algoritmo una
volta sola
Evitare la duplicazione del codice
Principio “refactoring to generalize”
Controllare le possibili estensioni di una classe
Fornire sia operazioni astratte sia operazioni hook (wrapper)
42Riccardo Cardin
43. Ingegneria del software mod. A
TEMPLATE METHOD
Struttura
43Riccardo Cardin
Definisce le operazione astratte
primitive. Definisce lo scheletro
dell’algoritmo
Implementa le operazioni
primitive fornendo i passi
concreti all’algoritmo
44. Ingegneria del software mod. A
TEMPLATE METHOD
Conseguenze
Tecnica per il riuso del codice
Fattorizzazione delle responsabilità
“The Hollywood principle”
Tipi di operazioni possibili
Operazioni concrete della classe astratta
Operazioni primitive (astratte)
Operazioni hook
Forniscono operazioni che di default non fanno nulla, ma
rappresentano punti di estensione
Documentare bene quali sono operazioni primitive e
quali hook
44Riccardo Cardin
45. Ingegneria del software mod. A
TEMPLATE METHOD
Esempio
45Riccardo Cardin
Esempio
Si vuole realizzare un set di funzioni per effettuare operazioni sugli
array. Si prevedono 2 funzioni aritmetiche:
- Somma di tutti gli elementi
- Prodotto di tutti gli elementi
46. Ingegneria del software mod. A
TEMPLATE METHOD
Esempio
Soluzione naive
46Riccardo Cardin
public int somma(int[] array) {
int somma = 0;
for (int i = 0; i < array.length; i++) {
somma += array[i];
}
return somma;
}
public int prodotto(int[] array){
int prodotto= 1;
for (int i = 0; i < array.length; i++) {
prodotto *= array[i];
}
return prodotto;
}
47. Ingegneria del software mod. A
TEMPLATE METHOD
Esempio
Soluzione con Template Method pattern
47Riccardo Cardin
public abstract class Calcolatore {
public final int calcola(int[] array){
int value = valoreIniziale();
for (int i = 0; i < array.length; i++) {
value = esegui(value, array[i]);
}
return value;
}
protected abstract int valoreIniziale();
protected abstract int esegui(int currentValue, int element);
}
public class CalcolatoreSomma {
protected int esegui(int currentValue, int element) {
return currentValue + element;
}
protected int valoreIniziale() {
return 0;
}
}
48. Ingegneria del software mod. A
TEMPLATE METHOD
Esempio
Scala: idioma, utilizzo high order function
Utilizzo metodi map, forall, flatMap, ...
Monads
...
48Riccardo Cardin
def doForAll[A, B](l: List[A], f: A => B): List[B] = l match {
case x :: xs => f(x) :: doForAll(xs, f)
case Nil => Nil
}
// Already in Scala specification
List(1, 2, 3, 4).map {x => x * 2}
49. Ingegneria del software mod. A
TEMPLATE METHOD
Esempio
Javascript: utilizzo delegation
Invocazione di un metodo è propagata ai livelli superiori
dell’albero dell’ereditarietà
49Riccardo Cardin
function AbsProperty(){
this.build = function() {
var result = this.doSomething();
return "The decoration I did: " + result;
};
}
OpenButton.prototype = new AbsProperty();
function OpenButton () {
this.doSomething = function() { return "open button"; };
}
SeeButton.prototype = new AbsProperty();
function SeeButton () {
this. doSomething = function() { return "see button"; };
}
var button = new SeeButton(); button.build();
Risale l’albero dei
prototipi
Ricerca nel contesto
del metodo
50. Ingegneria del software mod. A
TEMPLATE METHOD
Implementazione
Le operazioni primitive dovrebbero essere membri
protetti
Il template method non dovrebbe essere ridefinito
Java: dichiarazione “final”
Minimizzare il numero di operazioni primitive
… resta poco nel template method …
Definire una naming convention per i nomi delle
operazioni di cui effettuare override
50Riccardo Cardin
51. Ingegneria del software mod. A
RIFERIMENTI
Design Patterns, Elements of Reusable Object Oriented
Software, GoF, 1995, Addison-Wesley
Design Patterns
http://sourcemaking.com/design_patterns
Java DP
http://www.javacamp.org/designPattern/
Deprecating the Observer Pattern
http://lampwww.epfl.ch/~imaier/pub/DeprecatingObse
rversTR2010.pdf
Ruminations of a Programmer
http://debasishg.blogspot.it/2009/01/subsuming-
template-method-pattern.html
51Riccardo Cardin