Adapter Pattern is an example of some Demo implementations for OOP PHP Design Patterns in the Drupal 7 and Drupal 8 environments. Presentation at the Toronto Drupal Group
%in Harare+277-882-255-28 abortion pills for sale in Harare
Adapter design-pattern2015
1. Object Oriented Programming
Design Patterns
The Adapter Pattern
An example of Object Oriented PHP
Implementation for
< https://www.drupal.org/project/oop_design_patterns >
3. OOP Design Patterns: The Gang of Four!
It all started around 1994 when a group of 4 IBM programmers:
Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides
based on their coding experience , were able to observe and document
a set of about 23 common problems and their best accepted solutions
< https://www.drupal.org/project/oop_design_patterns >
4. OOP Design Patterns
What are design patterns?
Recurring solutions to common software development challenges
< https://www.drupal.org/project/oop_design_patterns >
O
5. OOP Design Patterns
Some common software development challenges:
➢ Building new applications while leveraging existing codebases
➢ Building/enhancing applications securely, quickly and effectively
➢ Integrating new and existing applications
➢ Multiple developers programming the same product
➢ Few developers programming many products
➢ Varying, sometimes unknown, data sources, OS, Setups
< https://www.drupal.org/project/oop_design_patterns >
6. OOP Design Patterns
What are design patterns not?
a) They are not the end to all of your coding challenges.
b) They are not a requirement of object oriented programming.
c) They are not a substitute for application code and logic.
d) They are not always the best solution for the job.
e) They are not always the easiest concept to grasp and/or use.
< https://www.drupal.org/project/oop_design_patterns >
b) DDT DRY DOT OnceAndOnlyOnce KISS/YAGNI PARETO
Don’t Do Twice Don’t Repeat Yourself Do One Thing Each and every declaration of behavior should appear Once (For) You ain't gonna need it 80effort/20functionality
normalization in the RelationalModel and removing redundancies 80%of code is crap
Programmers’ Code, Rule #27, Rules are best broken by those who have mastered them
7. OOP Design Patterns
GOF Classification for patterns
Creational
What: deal with object creation mechanisms
How: somehow controlling the object
creation
Example: Abstract Factory
Create a series of related objects without
specifying their distinct classes.
Usually all classes implements the same
interface.
< https://www.drupal.org/project/oop_design_patterns >
Structural
What: ease/simplify the design
How: by identifying a simple way to realize
relationships between entities.
Example: Adapter/Wrapper
Translate one interface for a class into a
compatible interface –by providing it’s interface
to clients while using the original interface.
Behavioral
What: identify common communication
patterns between objects
How: realizing these patterns
Example: Template Method
A skeleton of an algorithm, well-suited for
framework libraries. The user implements
one method and the superclass do the job.
8. OOP Design Patterns
The Adapter Pattern
Purpose: allows the interface of an existing class to be used from another
interface. It is often used to make existing classes work with others without
modifying their source code.
Examples where Adapter Pattern may help:
• I want to add search capabilities to my application and support
multiple search engines such as Google, Yahoo, Bing…
• Have an image loader for different kinds of images JPG, GIF, PNG…
• Use different Email providers: Gmail, Hotmail, YahooMail…
• Use different data sources: Db, XML, TXT, CSV…
• Connect to different Db: MySQL, PostgreSQL, MSSQL, Oracle
• Have multiple downloads using different protocols: HTTP, HTTPS, FTP…
• Use different payment providers: Moneris, AuthorizeNet, Skrill…
< https://www.drupal.org/project/oop_design_patterns >
9. OOP Design Patterns
If Client and Adaptee are incompatible, we may create
a new class called Adapter, and place it in between
Target and Adaptee.
Components become compatible with each other
through Adapter.
As long as some component integrates incompatible
interfaces, it can be considered an adapter.
< https://www.drupal.org/project/oop_design_patterns >
Usually Adaptee class
implements
the Target interface.
Client and Adaptee
are compatible!
10. OOP Design Patterns
PHP Adapter: When you've opened a can of worms, then the
only way to seal them again - Is using a bigger jar
< https://www.drupal.org/project/oop_design_patterns >
The Interface
Incompatible
classes
11. OOP Design Patterns
Design patterns are a great way to modularize your code
and create reusable structures.
But they mean nothing if they go unused.
Go code something.
< https://www.drupal.org/project/oop_design_patterns >
21. OOP Design Patterns
To be Continued...
Controller (GenRespAsignSoftPatt), Facade (GOF)
➢ Probably one of the most common patterns in OOP
➢ One of the most powerful patterns in development
➢ Opens a wealth of new possibilities, when understood
➢ Very flexible when favoring composition over inheritance
➢ Encapsulates what changes to allow for greater extendability
< https://www.drupal.org/project/oop_design_patterns >
22. OOP Design Patterns
Acknowledgments
Donquixote (Andreas Hennings)
For PHP Class loading suite (PSR-4)
https://www.drupal.org/project/xautoload
Nafes (Nik Alexandrov)
For Starting OOP examples in Drupal
https://www.drupal.org/project/oop_examples
< https://www.drupal.org/project/oop_design_patterns >