Retrofit is a library for Java and Android that allows making HTTP requests to REST APIs. It uses OkHttp for networking functions and can convert HTTP responses to Java objects using converters like Gson. To use Retrofit, add it and converter dependencies to the build file, create a Retrofit instance with the base URL and converter, define an interface for API requests, and call those methods to make asynchronous network requests that return response data.
Rust is a systems programming language that is fast, memory-efficient, and safe. It was created by Mozilla Research in 2010 and released in 2015. Rust uses a borrow checker to ensure memory safety at compile time without using garbage collection. It is suitable for writing system software, embedded applications, and web assembly. Rust aims to prevent common concurrency bugs and provides features like strong typing, pattern matching, and macros.
XML introduction and Uses of XML in JSBSimWai Nwe Tun
XML is used to define configuration files for JSBSim. These files describe aircraft metrics, mass properties, aerodynamic models, and systems. XML allows hierarchical definition of elements like tables, functions, and components. Runtime input and output is also specified to interface with JSBSim during simulation.
Hamcrest is a library for creating matchers for usage in unit tests, mocks and UI validation. This talk gives a brief introduction to using and writing Hamcrest matchers.
The topics covered:
* Basic introduction to Hamcrest
* Using Matchers in assertions
* Using Matchers with Mockito
* Writing custom matchers
* Ad-hoc matchers
HashMap is a part of Java's collection.. It provides the basic implementation of Map interface of Java. It stores the data in (Key, Value) pairs. To access a value key should be known. This ppt dives deep into the internal working of Hashmaps.
Retrofit is a library for Java and Android that allows making HTTP requests to REST APIs. It uses OkHttp for networking functions and can convert HTTP responses to Java objects using converters like Gson. To use Retrofit, add it and converter dependencies to the build file, create a Retrofit instance with the base URL and converter, define an interface for API requests, and call those methods to make asynchronous network requests that return response data.
Rust is a systems programming language that is fast, memory-efficient, and safe. It was created by Mozilla Research in 2010 and released in 2015. Rust uses a borrow checker to ensure memory safety at compile time without using garbage collection. It is suitable for writing system software, embedded applications, and web assembly. Rust aims to prevent common concurrency bugs and provides features like strong typing, pattern matching, and macros.
XML introduction and Uses of XML in JSBSimWai Nwe Tun
XML is used to define configuration files for JSBSim. These files describe aircraft metrics, mass properties, aerodynamic models, and systems. XML allows hierarchical definition of elements like tables, functions, and components. Runtime input and output is also specified to interface with JSBSim during simulation.
Hamcrest is a library for creating matchers for usage in unit tests, mocks and UI validation. This talk gives a brief introduction to using and writing Hamcrest matchers.
The topics covered:
* Basic introduction to Hamcrest
* Using Matchers in assertions
* Using Matchers with Mockito
* Writing custom matchers
* Ad-hoc matchers
HashMap is a part of Java's collection.. It provides the basic implementation of Map interface of Java. It stores the data in (Key, Value) pairs. To access a value key should be known. This ppt dives deep into the internal working of Hashmaps.
Mari Memahami PSR (PHP Standards Recommendation)Mizan Riqzia
Dokumen tersebut membahas tentang PHP Standards Recommendation (PSR) yang dikembangkan oleh PHP Framework Interop Group (PHP-FIG). PSR merupakan standar koding untuk PHP yang bertujuan agar berbagai framework PHP dapat saling bekerja sama dengan lebih baik."
This document provides an overview of porting Linux to a new ARM platform. It discusses setting up the GNU toolchain, kernel prerequisites and configuration, creating machine-specific files and code, initializing drivers and boot options. Key steps include registering the new machine, adding architecture-specific code and configuration files, initializing I/O mapping and IRQs, and creating an initramfs image to test bootability. References for further information on ARM Linux boot sequences and porting are also provided.
Rust has something unique to offer that languages in that space have never had before, and that is a degree of safety that languages like C and C++ have never had. Rust promises to deliver equivalent or better performance and greater productivity with guaranteed memory safety and data race freedom while allowing complete and direct control over memory.
This video will cover:
What is Rust?
Benefits of Rust
Rust Ecosystem
Popular Applications in Rust
The document introduces coroutines in Kotlin. It discusses how coroutines make asynchronous code easier to write by allowing suspending functions and avoiding callback hell. Coroutines were introduced in early languages like Simula but fell out of favor due to multithreading. They are now regaining popularity for writing asynchronous non-blocking code. The document then covers how coroutines work in Kotlin, including suspending functions, coroutine builders like launch and async, and how coroutines avoid issues with approaches like callbacks and futures. It notes that coroutines in Kotlin are currently experimental but can be used in production code.
An Introduction to Makefile.
about 23 slides to present you a quick start to the make utility, its usage and working principles. Some tips/examples in order to understand and write your own
Makefiles.
In this presentation you will learn why this utility continues to hold its top position in project build software, despite many younger competitors.
Visit Do you know Magazine : https://www.facebook.com/douknowmagazine
Chapitre 11: Expression Lambda et Référence de méthode en JavaAziz Darouichi
Voici le chapitre 11 sur les expressions lambda et les références de méthodes en Java.
Si vous avez des remarques ou suggestions afin de le parfaire.
N’hésitez pas à me contacter via mon email:
pr.azizdarouichi@gmail.com.
Bonne lecture.
Binder IPC allows processes to communicate by sharing common interface definitions. A client obtains a local proxy object and invokes methods which are translated to calls on a remote service object via the binder driver. Services register with the ServiceManager and clients obtain remote service objects by name. Calls involve parceling requests into ioctl calls between proxy helpers and remote helpers.
Understanding the Android System ServerOpersys inc.
This document discusses the Android system server. It provides an overview of the bootup sequence where the system server is started. It then describes some of the key services run by the system server, such as the activity manager, package manager, window manager, and others. It also discusses how to observe the system server in action using logcat and how applications interface with system services via Binder.
In this C# Web REST tutorial, beginners will learn first what a C# REST API is and then what are the HTTP Verbs in C# REST API is. Learn about the HTTP Status Codes in this C# tutorial. and we will become acquainted with all of the Constraints of the C# REST API. After that, for a better learning experience, we will see a practical demonstration of C# REST API in this C# programming tutorial. Finally we will wind up this session with Few takeaways on C# REST API.
Kotlin Coroutines allow for writing asynchronous non-blocking code using coroutines and suspending functions. Key features include cooperative multitasking on a single thread, using coroutines instead of threads, and dispatchers to control coroutine execution. Examples demonstrate loading data asynchronously for UI, updating multiple objects concurrently using coroutines, and checking server validity in a non-blocking suspending function.
Practical non blocking microservices in java 8Michal Balinski
How to write application in Java 8 that do not waste resources and which can maximize effective utilization of CPU/RAM. Comparison of blocking and non-blocking approach for I/O and application services. Based on microservices implementing simple business logic in security/cryptography/payments domain. Demonstration of following aspects:
* NIO at all edges of application
* popular libraries that support NIO
* single instance scalability
* performance metrics (incl. throughput and latency)
* resources utilization
* code readability with CompletableFuture
* application maintenance and debugging
All above based on our experiences gathered during development of software platforms at Oberthur Technologies R&D Poland.
The document discusses Project Reactor, a library for building asynchronous and non-blocking applications in Java or Kotlin. It explains the differences between blocking and non-blocking code, provides examples of using Project Reactor, and highlights some gotchas. Benchmarking results show that a non-blocking Dropwizard application using Project Reactor can handle over 12 times as many requests per second as a blocking version. The document also includes links to code samples on GitHub that demonstrate concepts like combining different publishers, exception handling, and caching.
This document discusses the Android multimedia framework on Jelly Bean. It provides an introduction to OpenMAX and describes the simple stack architecture including the developer API, event handler, surface holder, StageFright, OpenMAX interface, and software/hardware codecs. It explains the workflows and sequence flows for playing a media file, including setting the data source, preparing to play, and starting playback. Finally, it covers the synchronization architecture and flow of StageFright.
Algorithmique et methodes de programmationSageKataliko1
Ce module est l'Introduction du Cours d'algorithmique que nous enseignons aux Etudiants en Genie Informatique, Gestion Informatique, Informatique appliquée, ...
This document discusses RxJava, a library for composing asynchronous and event-based programs in Java. It introduces Observables as the core abstraction in RxJava, which are sequences that emit elements to observers. Operators like filter, map, and flatMap allow modifying and transforming Observables. As an example, it shows how to use RxJava to concurrently search for articles by ID, load each article, fetch like counts, and combine the results into a stream of articles. This is done by chaining flatMap operators to transform the stream of IDs into a stream of articles by asynchronously loading each part in parallel.
Mari Memahami PSR (PHP Standards Recommendation)Mizan Riqzia
Dokumen tersebut membahas tentang PHP Standards Recommendation (PSR) yang dikembangkan oleh PHP Framework Interop Group (PHP-FIG). PSR merupakan standar koding untuk PHP yang bertujuan agar berbagai framework PHP dapat saling bekerja sama dengan lebih baik."
This document provides an overview of porting Linux to a new ARM platform. It discusses setting up the GNU toolchain, kernel prerequisites and configuration, creating machine-specific files and code, initializing drivers and boot options. Key steps include registering the new machine, adding architecture-specific code and configuration files, initializing I/O mapping and IRQs, and creating an initramfs image to test bootability. References for further information on ARM Linux boot sequences and porting are also provided.
Rust has something unique to offer that languages in that space have never had before, and that is a degree of safety that languages like C and C++ have never had. Rust promises to deliver equivalent or better performance and greater productivity with guaranteed memory safety and data race freedom while allowing complete and direct control over memory.
This video will cover:
What is Rust?
Benefits of Rust
Rust Ecosystem
Popular Applications in Rust
The document introduces coroutines in Kotlin. It discusses how coroutines make asynchronous code easier to write by allowing suspending functions and avoiding callback hell. Coroutines were introduced in early languages like Simula but fell out of favor due to multithreading. They are now regaining popularity for writing asynchronous non-blocking code. The document then covers how coroutines work in Kotlin, including suspending functions, coroutine builders like launch and async, and how coroutines avoid issues with approaches like callbacks and futures. It notes that coroutines in Kotlin are currently experimental but can be used in production code.
An Introduction to Makefile.
about 23 slides to present you a quick start to the make utility, its usage and working principles. Some tips/examples in order to understand and write your own
Makefiles.
In this presentation you will learn why this utility continues to hold its top position in project build software, despite many younger competitors.
Visit Do you know Magazine : https://www.facebook.com/douknowmagazine
Chapitre 11: Expression Lambda et Référence de méthode en JavaAziz Darouichi
Voici le chapitre 11 sur les expressions lambda et les références de méthodes en Java.
Si vous avez des remarques ou suggestions afin de le parfaire.
N’hésitez pas à me contacter via mon email:
pr.azizdarouichi@gmail.com.
Bonne lecture.
Binder IPC allows processes to communicate by sharing common interface definitions. A client obtains a local proxy object and invokes methods which are translated to calls on a remote service object via the binder driver. Services register with the ServiceManager and clients obtain remote service objects by name. Calls involve parceling requests into ioctl calls between proxy helpers and remote helpers.
Understanding the Android System ServerOpersys inc.
This document discusses the Android system server. It provides an overview of the bootup sequence where the system server is started. It then describes some of the key services run by the system server, such as the activity manager, package manager, window manager, and others. It also discusses how to observe the system server in action using logcat and how applications interface with system services via Binder.
In this C# Web REST tutorial, beginners will learn first what a C# REST API is and then what are the HTTP Verbs in C# REST API is. Learn about the HTTP Status Codes in this C# tutorial. and we will become acquainted with all of the Constraints of the C# REST API. After that, for a better learning experience, we will see a practical demonstration of C# REST API in this C# programming tutorial. Finally we will wind up this session with Few takeaways on C# REST API.
Kotlin Coroutines allow for writing asynchronous non-blocking code using coroutines and suspending functions. Key features include cooperative multitasking on a single thread, using coroutines instead of threads, and dispatchers to control coroutine execution. Examples demonstrate loading data asynchronously for UI, updating multiple objects concurrently using coroutines, and checking server validity in a non-blocking suspending function.
Practical non blocking microservices in java 8Michal Balinski
How to write application in Java 8 that do not waste resources and which can maximize effective utilization of CPU/RAM. Comparison of blocking and non-blocking approach for I/O and application services. Based on microservices implementing simple business logic in security/cryptography/payments domain. Demonstration of following aspects:
* NIO at all edges of application
* popular libraries that support NIO
* single instance scalability
* performance metrics (incl. throughput and latency)
* resources utilization
* code readability with CompletableFuture
* application maintenance and debugging
All above based on our experiences gathered during development of software platforms at Oberthur Technologies R&D Poland.
The document discusses Project Reactor, a library for building asynchronous and non-blocking applications in Java or Kotlin. It explains the differences between blocking and non-blocking code, provides examples of using Project Reactor, and highlights some gotchas. Benchmarking results show that a non-blocking Dropwizard application using Project Reactor can handle over 12 times as many requests per second as a blocking version. The document also includes links to code samples on GitHub that demonstrate concepts like combining different publishers, exception handling, and caching.
This document discusses the Android multimedia framework on Jelly Bean. It provides an introduction to OpenMAX and describes the simple stack architecture including the developer API, event handler, surface holder, StageFright, OpenMAX interface, and software/hardware codecs. It explains the workflows and sequence flows for playing a media file, including setting the data source, preparing to play, and starting playback. Finally, it covers the synchronization architecture and flow of StageFright.
Algorithmique et methodes de programmationSageKataliko1
Ce module est l'Introduction du Cours d'algorithmique que nous enseignons aux Etudiants en Genie Informatique, Gestion Informatique, Informatique appliquée, ...
This document discusses RxJava, a library for composing asynchronous and event-based programs in Java. It introduces Observables as the core abstraction in RxJava, which are sequences that emit elements to observers. Operators like filter, map, and flatMap allow modifying and transforming Observables. As an example, it shows how to use RxJava to concurrently search for articles by ID, load each article, fetch like counts, and combine the results into a stream of articles. This is done by chaining flatMap operators to transform the stream of IDs into a stream of articles by asynchronously loading each part in parallel.
The Spring IoC container is at the core of the Spring Framework. The container will create the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction. The Spring container uses dependency injection (DI) to manage the components that make up an application.
Vous souhaitez savoir ce que vous prépare Apple et Google à la rentrée et prévoir les impacts sur vos applications applications mobile. le rapport de prévention Niji 2023 sur iOS et Android est disponible.
Alternative au Tramway de la ville de Quebec Rev 1 sml.pdfDaniel Bedard
CDPQ Infra dévoile un plan de mobilité de 15 G$ sur 15 ans pour la région de Québec. Une alternative plus économique et rapide, ne serait-elle pas posssible?
- Valoriser les infrastructures ferroviaires du CN, en créant un Réseau Express Métropolitain (REM) plutôt qu'un nouveau tramway ou une combinaison des 2.
- Optimiser l'utilisation des rails pour un transport combiné des marchandises et des personnes, en accordant une priorité aux déplacements des personnes aux heures de pointes.
- Intégrer un téléphérique transrives comme 3ème lien urbain dédiés aux piétons et cyclistes avec correspondance avec le REM.
- Le 3 ème lien routier est repensé en intégrant un tunnel routier qui se prolonge avec le nouveau pont de l'Île d'Orléans et quelques réaménagemet de ses chausées.
https://www.linkedin.com/in/bedarddaniel/
English:
CDPQ Infra unveils a $15 billion, 15-year mobility plan for the Quebec region. Wouldn't a more economical and faster alternative be possible?
Leverage CN's railway infrastructure by creating a Metropolitan Express Network (REM) instead of a new tramway or a combination of both.
Optimize the use of rails for combined freight and passenger transport, giving priority to passenger travel during peak hours.
Integrate a cross-river cable car as a third urban link dedicated to pedestrians and cyclists, with connections to the REM.
Rethink the third road link by integrating a road tunnel that extends with the new Île d'Orléans bridge and some reconfiguration of its lanes.
https://www.linkedin.com/in/bedarddaniel/
COUPROD Une méthode nationale commune à l’ensemble des filières herbivores
Le pattern adaptateur
1. Présentation sur
Le pattern Adaptateur
Presenté par Khaled Amirat
Supervisé par Mr Mezred Youcef
Département de mathématiques et d'informatique
Université de Souk Ahras, Algérie
2017
1
2. Design Patterns de structure (1)
Abstraction de la manière dont les classes et les objets sont
composés pour former des structures plus importantes.
Deux types de motifs
– Motifs de structure de classes .
– Motifs de structure d’objets .
3. Design Patterns de structure (2)
– Motifs de structure de classes
• Utilisation de l’héritage pour composer des interfaces et/ou des
implémentations (ex : Adapter).
– Motifs de structure d’objets
• composition d’objets pour réaliser de nouvelles fonctionnalités :
4. Adaptateur (patron de conception)
En génie logiciel, adaptateur (ou wrapper) est un patron de
conception (design pattern) de type structure (structural). Il permet de
convertir l'interface d'une classe en une autre interface que le client
attend.
L’adaptateur fait fonctionner ensemble des classes qui n'auraient
pas pu fonctionner sans lui, à cause d'une incompatibilité d'interfaces.
5. Applicabilité (1)
Il permet d'intégrer une classe à ne pas modifier, par exemple :
● Une API tiers convient au besoin fonctionnel, mais la signature
de ses méthodes ne convient pas.
● L'utilisation d'anciennes classes doit être normalisée, sans pour
autant en reprendre tout le code.
6. Applicabilité (2)
Un objet adaptateur sert de liaison entre les objets manipulés et un
programme les utilisant, permettant la communication entre classes.
Il est utilisé pour convertir l'interface d'un objet vers une autre
interface, attendue par le client pour utiliser l'objet en question.
7. Structure
Une cible ( IAdaptateur ) définit l’interface spécifique à
l’application app ca o que le e client c e utilise .
Le Client collabore avec les objets qui sont conformes à l’interface
de IAdaptateur .
L classe l à adapter d t ( Adapté é ) est t l’interface l’i t f existante i t t
qui i a besoin d’adaptation .
L’adaptateur p ( Adaptateur p ) adapte p effectivement l’interface
de Adapté à l’interface de IAdaptateur par traduction des accès
9. Example (1)
Une société souhaite produire un chargeur universel de batteries pour téléphone portable pouvant délivrer jusqu'à
10 volts en sortie. Les ingénieurs ont produit un premier prototype de chargeur:
public class Chargeur
{
// le portable branché sur le chargeur
private IChargeable telephone;
// le voltage en sortie du chargeur
private const int voltage = 10;
// branchement d'un portable pour le charger
public void brancherPortable(IChargeable portable)
{
System.out.println("branchement d'un portable");
this.telephone = portable;
this.telephone.Recharger(voltage);
}
}
10. Example (2)
Celui-ci est capable de se brancher sur tout téléphone implémentant l'interface
IChargeable via la méthode brancherPortable et de le recharger en produisant 10 volts en
sortie.
public interface IChargeable
{
/*
méthode appelée si l'on veut recharger le portable
*/
/* @param name="volts" voltage en sortie du chargeur */
void Recharger(int volts);
}
11. Example (3)
Celui-ci est capable de se brancher sur tout téléphone implémentant l'interface
IChargeable via la méthode brancherPortable et de le recharger en produisant 10 volts en
sortie.
public interface IChargeable{
/* méthode appelée si l'on veut recharger le portable
/* @param name="volts" voltage en sortie du chargeur */
void Recharger(int volts);
}
12. Example (4)
On créé plusieurs téléphones portables de test qui implémentant l'interface IChargeable
dont Comme suit:
public class PortableDeTest Implements IChargeable
{
public void Recharger(int volts)
{
System.out.println( "Portable de test en charge" );
System.out.println( "voltage: {0}" , volts);
}
}
13. Example (5)
Les tests effectués en laboratoire sont concluants. Le chargeur fonctionne à la perfection
avec tous les téléphones implémentant l'interface IChargeable.
Cependant les problèmes apparaissent lors de tests avec les téléphones portables
actuellement sur le marché (par exemple avec la marque Oppo ou encore Condor ). En effet,
chaque fabriquant de téléphone propose son propre système de chargement. Les interfaces
sont non seulement différentes mais le voltage utilisé varie aussi d'un téléphone à l'autre
(allant de 10 à 5 volts). Le chargeur universel ne l'est alors plus du tout. Il devient donc
impossible d'utiliser Ce chargeur avec les téléphones existants. Malheur, la faillite sonne à la
porte de la société!
14. Example (6)
Proposition des solution
"Nous avons besoin que les téléphones implémentent l'interface IChargeable mais nous
ne pouvons pas les modifier nous même. Nous n'en possédons pas le code source. Il nous
suffit donc de proposer notre interface IChargeable aux différents constructeurs et de leur
demander de l'implémenter dans leur téléphone."
15. Example (7)
Prenons un exemple courant
"les prises électriques. Si vous voyagez en Angleterre par exemple et tentez de brancher
une fiche électrique française sur la prise murale anglaise vous risquez d'avoir quelques
problèmes, les interfaces n'étant pas compatibles. Alors que faites vous ? Vous descendez au
magasin de bricolage du quartier pour acheter un adaptateur. Un coté de l'adaptateur s'adapte
à l'interface de la prise murale anglaise tandis que l'autre s'adapte à la fiche française. Au
milieu s'opèrent des transformations afin que les deux cotés puissent communiquer."
16. Example (8)
Back Again ! Proposition des solution
Opposition "Les constructeurs ont leur propre système et n'ont pas l'intention de le
changer. Tu imagines s'ils devaient prendre en compte les demandes des centaines de
constructeurs de chargeurs et autres périphériques, ils ne s'en sortiraient pas. Et puis que
faire des téléphones déjà vendus ?
Ils n'implémenteraient pas IChargeable et ne pourraient donc pas être utilisés par notre
chargeur !" "Ce n'est donc pas au fabriquant du portable à modifier son code mais à nous de
nous y adapter. Adapter, voilà un mot intéressant. Ce qu'il nous faudrait c'est en fait quelque
chose qui puisse adapter le code des téléphones pour que notre chargeur puisse l'utiliser, un
adaptateur en somme."
17. Example (9)
Proposition des solution
Donc !! "Nous allons créer un adaptateur pour chaque portable que l'on voudra utiliser
avec notre chargeur. Nous aurons donc un chargeur unique dont le code ne changera pas
auquel nous pourrons brancher n'importe quel téléphone en utilisant le bon adaptateur."
18. Example (10)
Occupons nous d'abord du côté s'interfaçant avec le chargeur. Ce dernier ne manipule
que des objets de type IChargeable.
L'adaptateur va devoir implémenter l'interface IChargeable afin que le chargeur puisse
l'utiliser.
Pour le coté s'adaptant au portable, l'adaptateur devra posséder une référence sur le
portable qu'il est censé adapter.
C'est en effet l'adaptateur qui manipulera directement l'instance du portable et non pas le
chargeur.
19. Example (11)
public class PortableOppo{
// ne se recharge qu'avec du 10 volts
public void ChargerBatteries(int volts)
{
System.out.println("Portable SonneEricSonne en charge");
System.out.println("voltage: {0}", volts);
}
}
public class PortableCondor{
// ne se recharge qu'avec du 5 volts
public void ChargerPortable(int volts)
{
System.out.println("Portable SamSaoule en charge");
System.out.println("voltage: {0}", volts);
}
}
Étudions deux exemples de téléphones portables: SonneEricSonne et SamSaoule. Voici
les classes les représentants:
20. Example (12)
Nous allons donc construire un adaptateur pour chaque téléphone. Voici tout d'abord
l'adaptateur pour téléphones SonneEricSonne:
AdaptateurOppo
Class
PortableOppo
Class
telephone : PortableOppo
AdaptateurOppo()
Recharger() : void
PortableOppo
21. Example (13)
public class AdaptateurOppo Implements IChargeable{
// référence sur le portable adapté
private PortableSonneEricSonne telephone ;
public AdaptateurOppo( PortableOppo portable)
{
this.telephone = portable;
}
public void Recharger(int volts)
{
this.telephone.ChargerBatteries( volts);
}
}
22. Example (14)
L'adaptateur implémente l'interface IChargeable afin de pouvoir être manipulé par le
chargeur.
Nous utilisons le constructeur de l'adaptateur afin de lui donner une référence sur le
téléphone qu'il est censé adapter.
Nous gardons cette référence via un champ privé. Il ne reste plus qu'à saisir le code de la
méthode Recharger.
Le chargeur appelle cette méthode en passant en paramètre le voltage.
L'adaptateur se charge d'envoyer cet appel au téléphone dont il s'occupe (lui seul sait
comment manipuler un téléphone Oppo).
Passons maintenant à l'adaptateur pour téléphones Condor.
23. Example (15)
AdaptateurCondor
Class
PortableCondor
Class
telephone : PortableCondor
AdaptateurCondor()
Recharger() : void
PortableCondor
public class AdaptateurCondor Implements IChargeable{
// référence sur le portable adapté
private PortableCondor telephone;
public AdaptateurCondor(PortableCondor portable){
this.telephone = portable;
}
//le portable SamSaoule n'a besoin que de 5 volts
public void Recharger(int volts){
//on modifie le voltage
int nouveauVoltage = volts > 5 ? 5 : volts ;
this.telephone.ChargerPortable(nouveauVoltage);
}
}
24. Example (16)
Rien d'extraordinaire par rapport à l'adaptateur précédent. La nouveauté se situe au
niveau de la méthode Recharger. Ici l'adaptateur ne se contente pas simplement de traduire
les appels du chargeur vers le portable. Vous vous souvenez sans doute que les portables
Condor n'ont besoin que de 5 volts. Et bien c'est l'adaptateur qui va se charger d'effectuer la
transformation. L'adaptateur encapsule toutes les différences entre le chargeur et le portable.
Le chargeur n'a donc aucun lien avec le portable, seul l'adaptateur connait les spécificités de ce
dernier. D'ailleurs, si vous réfléchissez, vous verrez qu'en fait le chargeur ne sait même pas
que c'est un téléphone portable qu'il est en train de charger. La société a bien compris. Elle
s'est donc empressée de créer des adaptateurs pour toute sorte d'appareils (piles
rechargeables, balladeurs MP3, etc.) tout en gardant le même chargeur de départ. Maintenant
que les adaptateurs sont créés, il ne reste plus qu'à les tester. Voici donc un petit programme
en mode console:
25. Example (17)
static void Main(string[] args){
//on crée le chargeur
Chargeur chargeur = new Chargeur();
/******************** Portable Oppo***********************/
//on crée le portable et son adaptateur
PortableOppo portableOp = new PortableOppo();
AdaptateurOppo adapateurOp = new AdaptateurOppo( portableOp);
//on donne le portable à charger mais en utilisant son adaptateur
chargeur.brancherPortable( adapateurOp);
System.out.println( );
/********************* Portable Condor***************************/
//on crée le portable et son adaptateur
PortableCondor portableCo = new PortableSamSaoule( );
AdaptateurCondor adapateurCo = new AdaptateurCondor( portableCon);
//on donne le portable à charger mais en utilisant son adaptateur
chargeur.brancherPortable( adapateurCon);
}
26. Example (18)
Execution :
branchement d’un portable
portableOppo on charge
voltage : 10
branchement d’un portable
portableCondor on charge
voltage : 6
Comme vous le voyez, les adaptateurs ont parfaitement fonctionné. Nous avons pu
recharger des téléphones de marques différentes grâce aux adaptateurs. De plus,
l'adaptateur pour téléphone SamSaoule a bien adapté le voltage en le ramenant à 5.
27. Conséquences
Pour la classe de l’objet qui adapte
Pas possible d’adapter une classe et ses sous sous-classes classes .
Mais redéfinition possible du comportement (sous-classe) .
Pour l’objet qui adapte
Un Adaptateur peut travailler avec plusieurs Adaptées .
Plus difficile de redéfinir le comportement d d’Adaptée Adaptée (sous- (sous
classer puis obliger Adaptateur à référencer la sous-classe) .
28. Conclusion
Ici s'achève notre découverte du pattern Adaptateur. A partir
de maintenant lorsque vous devrez utiliser une classe existante
et que son interface ne correspond pas à celle que vous attendez,
vous saurez quoi faire.