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 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.
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 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.
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 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 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.
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.
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 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.
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 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.
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 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 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.
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.
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 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.
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 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.
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.
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
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.
The document discusses the pros and cons of the Scala programming language. It outlines some of the good aspects of Scala like its functional and object-oriented nature, immutable collections, and ability to reuse Java libraries. However, it also notes challenges like slow compiler and IDE tools, a steep learning curve, and the potential for overly complex code. While Scala has drawbacks, the author believes it could be suitable for small side modules but not general new projects due to its deficiencies, and that guidelines are needed to prevent misuse of its expressive capabilities.
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 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 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.
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.
Presto was updated from version 0.152 to 0.178. New features in the update include lambda expressions, filtered aggregation, a VALIDATE mode for EXPLAIN, compressed exchange, and complex grouping operations. The update also added new functions and deprecated some legacy features with warnings. Future work on Presto includes disk spill optimization and a cost-based optimizer.
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.
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.
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 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.
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.
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
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.
The document discusses the pros and cons of the Scala programming language. It outlines some of the good aspects of Scala like its functional and object-oriented nature, immutable collections, and ability to reuse Java libraries. However, it also notes challenges like slow compiler and IDE tools, a steep learning curve, and the potential for overly complex code. While Scala has drawbacks, the author believes it could be suitable for small side modules but not general new projects due to its deficiencies, and that guidelines are needed to prevent misuse of its expressive capabilities.
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 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 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.
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.
Presto was updated from version 0.152 to 0.178. New features in the update include lambda expressions, filtered aggregation, a VALIDATE mode for EXPLAIN, compressed exchange, and complex grouping operations. The update also added new functions and deprecated some legacy features with warnings. Future work on Presto includes disk spill optimization and a cost-based optimizer.
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.
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.
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 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 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 the main features of Scala, an object oriented and functional programming language. The main focus of the slides is to show how the language implements natively some of the patterns and best practices that are no present in other programming languages, such as Java, C++ and so on.
In detail, the presentation spans these concepts:
- Language's main syntax
- Classes, abstract classes, objects and traits (mixin)
- The Option class
- An introduction to generics
- Implicit classes
- Functions
- Recursion (simple and tail)
- Currying
- Call by value / name
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation is based on Joakim\’s experiences from moving from Java to Scala http://www.scala-lang.org/node/960#Joak We will explore how to move from Java to Scala and why. We\’ll look at things that you will run into sooner rather than later such as Scala\’s collection APIs, Options and higher order functions and special syntax. You will leave this presentation with good foundation to use Scala in practice; perhaps even in your current Java project and ideally with an appetite to learn more.
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 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.
Layered Expression Trees: una terza via (idiomatica) verso il DDDAndrea Saltarello
Abbiamo il nostro splendido Domain Model, e possiamo passare la vita a definire DTO per usarlo in modo “sostenibile”. Oppure possiamo metterlo (un po’) in disparte ed adottare CQRS, ammesso che non ci venga mai da dire: “che spreco”. Oppure possiamo optare per una terza via idiomatica: Layered Expression Trees. Parliamone.
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.
My Graduation discussion (20 mins version), for thesis : Review - IT a Social Network for Scientific documents discussion; developed by integrating GWT,SPRING, HIBERNATE, MAVEN.
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.
Introduzione al Domain Driven Design (DDD)DotNetMarche
In questa sessione si approfondirà il concetto di Domain Driven Design, un principio di progettazione che può essere visto come una “forma-mentis” per aiutare a concepire e modellare applicazioni enterprise che fanno un forte uso del Domain Model. Questa metodologia, introdotta da Eric Evans, mette in risalto il dominio applicativo di un progetto, costituendo quindi il collante tra il modello analitico e il modello implementativo e trovando la sua naturale applicazione in ambienti di sviluppo agili come Extreme Programming. Come completamento della sessione verranno esaminate alcune tecniche di Layering e pattern architetturali che ben si sposano con questa tecnica.
Dal RenderFragment ai Generics, tips for Blazor developersAndrea Dottor
Sessione tenuta alla Blazor Conference 2021 del 13.04.2021.
(https://www.aspitalia.com/eventi/87/Blazor-Conference-2021-Online.aspx)
Una sessione dove verranno presentati una serie di tips per migliorare e facilitare la scrittura delle nostre applicazioni: da codice html dinamico, al miglioramento ed organizzazione dello stesso. Il tutto per poter sfruttare ogni bit che Blazor può dare. Dal RenderFragment ai Generics. Consigli che arrivano da esperienze reali
Codice: https://github.com/andreadottor/XE.Dottor.Demo.BlazorWebApp
1. DESIGN PATTERN STRUTTURALI
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
DESIGN PATTERN STRUTTURALI
2Riccardo Cardin
Architetturali
Model view controller
3. Ingegneria del software mod. A
INTRODUZIONE
Scopo dei design pattern strutturali
Affrontare problemi che riguardano la composizione
di classi e oggetti
Consentire il riutilzzo degli oggetti esistenti fornendo
agli utilizzatori un’interfaccia più adatta
Integrazioni fra librerie / componenti diverse
Sfruttano l’ereditarietà e l’aggregazione
3Riccardo Cardin
4. Ingegneria del software mod. A
ADAPTER
Scopo
Convertire l’interfaccia di una classe in un’altra.
Motivazione
Spesso i toolkit non sono riusabili
Non è corretto (e possibile) modificare il toolkit!
Definiamo una classe (adapter) che adatti le interfacce.
Per ereditarietà o per composizione
La classe adapter può fornire funzionalità che la classe adattata
non possiede
4Riccardo Cardin
5. Ingegneria del software mod. A
ADAPTER
Applicabilità
Riutilizzo di una classe esistente, non è conforme
all’interfaccia target
Creazione di classi riusabili anche con classi non
ancora analizzate o viste
Non è possibile adattare l’interfaccia attraverso
ereditarietà (Object adapter)
5Riccardo Cardin
6. Ingegneria del software mod. A
ADAPTER
Struttura
Class adapter
Object adapter
6Riccardo Cardin
Interfaccia di
dominio Interfaccia esistente, che
deve essere adattata
Adatta l’interfaccia di
Adaptee a Target
7. Ingegneria del software mod. A
ADAPTER
Conseguenze
Class adapter
Non funziona quando bisogna adattare una classe e le sue
sottoclassi
Permette all’Adapter di modificare alcune caratteristiche
dell’Adaptee
Object adapter
Permette ad un Adapter di adattare più tipi (Adaptee e le sue
sottoclassi)
Non permette di modificare le caratteristiche dell’Adaptee
Un oggetto adapter non è sottotipo dell’adaptee
7Riccardo Cardin
8. Ingegneria del software mod. A
ADAPTER
Esempio
8Riccardo Cardin
Convertire (adattare) una vecchia classe Rectangle ad una nuova
interfaccia Polygon.
9. Ingegneria del software mod. A
ADAPTER
Esempio
Class adapter
9Riccardo Cardin
class RectangleClassAdapter {
// ...
public float[] getCoordinates() {
return new float[]{
getOriginX(),
getOriginY(),
getOppositeCornerX(),
getOppositeCornerY()};
}
// ...
}
10. Ingegneria del software mod. A
ADAPTER
Esempio
Object adapter
10Riccardo Cardin
Wrapping
class RectanglObjectAdapter {
// ...
public float[] getCoordinates() {
return new float[]{
adaptee.getOriginX(),
adaptee.getOriginY(),
adaptee.getOppositeCornerX(),
adaptee.getOppositeCornerY()};
}
// ...
}
11. Ingegneria del software mod. A
ADAPTER
Esempio
Scala: classi implicite
11Riccardo Cardin
trait Log {
def warning(message: String)
def error(message: String)
}
final class Logger {
def log(level: Level, message: String) { /* ... */ }
}
implicit class LoggerToLogAdapter(logger: Logger) extends Log {
def warning(message: String) { logger.log(WARNING, message) }
def error(message: String) { logger.log(ERROR, message) }
}
val log: Log = new Logger() Scala utilizza il costruttore per
eseguire la conversione
implicita
12. Ingegneria del software mod. A
ADAPTER
Esempio
Javascript: ...non ci sono classi, ma oggetti...
12Riccardo Cardin
// Adaptee
AjaxLogger.sendLog(arguments);
AjaxLogger.sendInfo(arguments);
AjaxLogger.sendDebug(arguments);
var AjaxLoggerAdapter = {
log: function() {
AjaxLogger.sendLog(arguments);
},
info: function() {
AjaxLogger.sendInfo(arguments);
},
debug: function() {
AjaxLogger.sendDebug(arguments);
},
...
};
window.console = AjaxLoggerAdapter;
Uso funzioni e namespace
per simulare le classi e gli
oggetti
13. Ingegneria del software mod. A
ADAPTER
Implementazione
Individuare l’insieme minimo di funzioni (narrow) da
adattare
Più semplice da implementare e manutenere
Utilizzo di operazioni astratte
Diverse varianti strutturali alternative
(Client – Target) + Adapter
Client + Target + Adapter
13Riccardo Cardin
14. Ingegneria del software mod. A
DECORATOR
Scopo
Aggiungere responsabilità a un oggetto
dinamicamente
Motivazione
Il Decorator ingloba
un componente in un
altro oggetto che aggiunge la funzionalità
Il subclassing non può essere sempre utilizzato
Funzionalità aggiunte prima o dopo l’originale
14Riccardo Cardin
15. Ingegneria del software mod. A
DECORATOR
Applicabilità
Aggiungere funzionalità dinamicamente ad un
oggetto in modo trasparente
Funzionalità che possono essere “circoscritte”
Estensione via subclassing non è possibile
Esplosione del numero di sottoclassi
Non disponibilità della classe al subclassing
15Riccardo Cardin
16. Ingegneria del software mod. A
DECORATOR
Struttura
16Riccardo Cardin
Interfaccia degli oggetti
da estendere
Oggetto da
estendere
Permette la decorazione
(“ricorsione”)
Aggiungono le
funzionalità al
componente
17. Ingegneria del software mod. A
DECORATOR
Struttura
17Riccardo Cardin
Classe concreta
Prima (o dopo)
dell’invocazione del
metodo della classe
concreta, esegue
operazioni
aggiuntive
(decorazioni)
18. Ingegneria del software mod. A
DECORATOR
Conseguenze
Maggiore flessibilità della derivazione statica
Evita classi “agglomerati di funzionalità” in posizioni
alte delle gerarchia
La classi componenti diventano più semplici
Software as a Service (SaaS)
Il decoratore e le componenti non sono uguali
Non usare nel caso in cui la funzionalità si basi sull’identità
Proliferazione di piccole classi simili
Facili da personalizzare, ma difficili da comprendere e testare.
18Riccardo Cardin
19. Ingegneria del software mod. A
DECORATOR
Esempio
19Riccardo Cardin
Si possiede un modello di gestione di oggetti che rappresentano gli
impiegati (Employee) di una azienda. Il sistema vuole prevedere la
possibilità di “promuovere” gli impiegati con delle responsabilità
aggiuntive (e adeguato stipendio :P ).
Ad esempio, da impiegato a capoufficio (AdministrativeManager)
oppure da impiegato a capo progetto (ProjectManager).
Nota: Queste responsabilità non si escludono tra di loro.
20. Ingegneria del software mod. A
DECORATOR
Esempio
20Riccardo Cardin
Classe base a cui
aggiungere funzionalità Decorator
Classi che aggiungono
funzionalità ad Engineer
21. Ingegneria del software mod. A
DECORATOR
Esempio
ORM is an Offensive Anti-Pattern
http://www.yegor256.com/2014/12/01/orm-
offensive-anti-pattern.html
Buon esempio di decorator utilizzato come cache (può essere
visto anche come esempio di proxy pattern)
21Riccardo Cardin
22. Ingegneria del software mod. A
DECORATOR
Esempio
Javascipt: gli oggetti sono dei "dizionari" di valori
22Riccardo Cardin
function Engineer( name, office){
//...
this.whois = function() { console.log(“I’m an engineer") ; }
}
var ProjectManager = new Engineer("Riccardo", "Development");
projectManager.whois = function() { console.log("I’m the boss!"); }
// What we're going to decorate
function Engineer() {
//...
}
/* Decorator 1 */
function AdministrativeManager(engineer) {
var v = engineer.whois();
engineer.whois = function() {
return v + console.log(" and I’m the super boss too!");
}
}
Multiple decorator
1
2
23. Ingegneria del software mod. A
DECORATOR
Esempio
Scala: mixin
23Riccardo Cardin
trait Employee {
// ...
def whois(): String
}
class Engineer(name: String, office: String) extends Employee
{ /* ... */ }
trait ProjectManager extends Employee {
abstract override def whois() {
// super rappresenta il mixin a sinistra
super.whois(buffer)
println("and I’am a project manager too!")
}
}
new Engineer("Riccardo","Development") with ProjectManager
Decorator con static
binding
24. Ingegneria del software mod. A
DECORATOR
Implementazione
Interfaccia del decoratore DEVE essere conforme a
quella del componente
Omissione della classe astratta del decoratore
… grandi gerarchie di classi già presenti …
Mantenere “leggera” (stateless) l’implementazione
del Component
Modifica della “pelle” o della “pancia”?
Decorator: quando le componenti sono “leggere”
Strategy: quando le componenti hanno un’implementazione
corposa
Evita decoratori troppo “costosi” da manutenere.
24Riccardo Cardin
25. Ingegneria del software mod. A
FACADE
Scopo
Fornire un’interfaccia unica semplice per un sottosistema
complesso
Motivazione
Strutturazione di un sistema in sottosistemi
Diminuisce la complessità del sistema, ma aumenta le dipendenze
tra sottosistemi
L’utilizzo di un Facade semplifica queste dipendenze
Ma non nasconde le funzionalità low-level
25Riccardo Cardin
27. Ingegneria del software mod. A
FACADE
Applicabilità
Necessità di una singola interfaccia semplice
Design pattern tendono a generare tante piccole classi
Vista di default di un sottosistema
Disaccoppiamento tra sottosistemi e client
Nasconde i livelli fra l’astrazione e l’implementazione
Stratificazione di un sistema
Architettura Three tier
27Riccardo Cardin
28. Ingegneria del software mod. A
FACADE
Struttura
28Riccardo Cardin
Associa ogni richiesta
ad una classe del
sottosistema,
delegando la rispostaImplementano le
funzionalità del
sottosistema, non avendo
conoscenza del Facade
Il client può interagire con il
Facade o con le singole
componenti
30. Ingegneria del software mod. A
FACADE
Conseguenze
Riduce il numero di classi del sottosistema con cui il
client deve interagire
Realizza un accoppiamento lasco tra i sottosistemi e i
client
Eliminazione delle dipendenze circolari
Aiuta a ridurre i tempi di compilazione e di building
Non nasconde completamente le componenti di un
sottosistema
Single point of failure
Sovradimensionamento della classe Facade
30Riccardo Cardin
31. Ingegneria del software mod. A
FACADE
Esempio
31Riccardo Cardin
All’interno di un’applicazione si vuole consentire la lettura da tastiera di
tipi di dati diversi (es. interi, float, stringhe, ecc).
Il pattern Facade permette
l’utilizzo di una classe
ConsoleReader che
espone i metodi di lettura e
incapsula le regole degli
effettivi strumenti di lettura.
32. Ingegneria del software mod. A
FACADE
Esempio
Javascript: utilizzato spesso con module pattern
32Riccardo Cardin
var module = (function() {
var _private = {
i:5,
get : function() {console.log( "current value:" + this.i);},
set : function( val ) {this.i = val;},
run : function() {console.log( "running" );},
};
return {
facade : function( args ) {
_private.set(args.val);
_private.get();
if ( args.run ) {
_private.run();
}
}
};
}());
Metodi privati
Metodo pubblico
33. Ingegneria del software mod. A
FACADE
Esempio
Scala: mixin
33Riccardo Cardin
trait ToolA {
//stateless methods in ToolA
}
trait ToolB {
//stateless methods in ToolB
}
trait ToolC {
//stateless methods in ToolC
}
object facade extends ToolA with ToolB with ToolC
Versione modificata del facade,
dove si hanno a disposizione tutti i
metodi delle classi del sottosistema
34. Ingegneria del software mod. A
FACADE
Implementazione
Classe Facade come classe astratta
Una classe concreta per ogni “vista” (implementazione) del
sottosistema
Gestione di classi da più sottosistemi
Definizione d’interfacce “pubbliche” e “private”
Facade nasconde l’interfaccia “privata”
Module pattern in Javascript
Singleton pattern: una sola istanza del Facade
34Riccardo Cardin
35. Ingegneria del software mod. A
PROXY
Scopo
Fornire un surrogato di un altro oggetto di cui si vuole
controllare l’accesso
Motivazione
Rinviare il costo di creazione di un oggetto
all’effettivo utilizzo (on demand)
Il proxy agisce come l’oggetto che ingloba
Stessa interfaccia
Le funzionalità dell’oggetto “inglobato” vengono
accedute attraverso il proxy.
35Riccardo Cardin
36. Ingegneria del software mod. A
PROXY
Applicabilità
Remote proxy
Rappresentazione locale di un oggetto che si trova in uno
spazio di indirizzi differente
Classi stub in Java RMI
Virtual proxy
Creazione di oggetti complessi on-demand
Protection proxy
Controllo degli accessi (diritti) all’oggetto originale
Puntatore “intelligente”
Gestione della memoria in Objective-C
36Riccardo Cardin
37. Ingegneria del software mod. A
PROXY
Struttura
37Riccardo Cardin
Definisce l’interfaccia comune che
permette di utilizzare il proxy come
l’oggetto inglobato.
L’oggetto rappresentato
dal proxy
Attraverso il puntatore al RealSubject,
permette l’accesso controllato alle sue
funzionalità
38. Ingegneria del software mod. A
PROXY
Conseguenze
Introduce un livello di indirezione che può essere
“farcito”
Remote proxy, nasconde dove un oggetto risiede
Virtual proxy, effettua delle ottimizzazioni
Protection proxy, definisce ruoli di accesso alle informazioni
Copy-on-write
La copia di un oggetto viene eseguita unicamente quando la
copia viene modificata.
38Riccardo Cardin
39. Ingegneria del software mod. A
PROXY
Esempio
Java RMI
39Riccardo Cardin
Il main chiede e ottiene attraverso una factory un oggetto Math
(lookup); su questo chiama il metodo somma. Il main usa
l’oggetto filtrato, come se fosse quello reale.
40. Ingegneria del software mod. A
PROXY
Implementazione
Implementazione “a puntatore”
Overload operatore -> e * in C++
Alcuni proxy , invece, agiscono in modo differente
rispetto alle operazioni
In Java costruzione tramite reflection (Spring, H8...)
Proxy per più tipi …
… subject è una classe astratta …
… ma non se il proxy deve istanziare il tipo concreto!
Rappresentazione del subject nel proxy
40Riccardo Cardin
41. 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/
Exploring the Decorator Pattern in Javascript
http://addyosmani.com/blog/decorator-pattern/
Design Patterns in Scala http://pavelfatin.com/design-patterns-in-
scala
Implicit Classes http://docs.scala-
lang.org/overviews/core/implicit-classes.html
Create Facade by combining scala objects/traits
http://stackoverflow.com/questions/14905473/create-facade-by-
combining-scala-objects-traits
Ruby Best Practices
http://blog.rubybestpractices.com/posts/gregory/060-issue-26-
structural-design-patterns.html
41Riccardo Cardin