SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Object Oriented Programming
Design Patterns
The Adapter Pattern
An example of Object Oriented PHP
Implementation for
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
Links
Drupal.org: VicOnt, nafes
Presentation Code:
https://www.drupal.org/project/oop_design_patterns
https://www.drupal.org/project/oop_examples
< https://www.drupal.org/project/oop_design_patterns >
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 >
OOP Design Patterns
What are design patterns?
Recurring solutions to common software development challenges
< https://www.drupal.org/project/oop_design_patterns >
O
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 >
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
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.
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 >
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!
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
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 >
OOP Design Patterns
The Problem: multiple Payment Providers
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
The Solution: Adapter/Wrapper for Providers 1, 3
< https://www.drupal.org/project/oop_design_patterns >
Scope res op
OOP Design Patterns
The Solution: Adapter/Wrapper for Provider 2
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
Adapter Pattern: UML diagram, programming to the interface
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
Adapter Pattern: Easy of use, programming to the interface
OOP Design Patterns
Adapter Pattern: Drupal 7 implementation
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
Adapter Pattern: Drupal 8 implementation
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
CodeCase in action:
< https://www.drupal.org/project/oop_design_patterns >
OOP Design Patterns
CodeCase in action:
< https://www.drupal.org/project/oop_design_patterns >
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 >
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 >

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Insight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FPInsight into java 1.8, OOP VS FP
Insight into java 1.8, OOP VS FP
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 
Whats Newi in C# 8.0
Whats Newi in C# 8.0Whats Newi in C# 8.0
Whats Newi in C# 8.0
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC TeamAOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
 
Code refactor strategy part #1
Code refactor strategy part #1Code refactor strategy part #1
Code refactor strategy part #1
 
Scala - By Luu Thanh Thuy CWI team from eXo Platform SEA
Scala - By Luu Thanh Thuy CWI team from eXo Platform SEAScala - By Luu Thanh Thuy CWI team from eXo Platform SEA
Scala - By Luu Thanh Thuy CWI team from eXo Platform SEA
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting started
 
The Economics of OptimJ
The Economics of OptimJThe Economics of OptimJ
The Economics of OptimJ
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practice
 
Typescript overview
Typescript overviewTypescript overview
Typescript overview
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Design Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract FactoryDesign Patterns - Factory Method & Abstract Factory
Design Patterns - Factory Method & Abstract Factory
 

Andere mochten auch

Proxy & adapter pattern
Proxy & adapter patternProxy & adapter pattern
Proxy & adapter pattern
babak danyal
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)
APU
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
achraf_ing
 
Design pattern tutorial
Design pattern tutorialDesign pattern tutorial
Design pattern tutorial
Piyush Mittal
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 

Andere mochten auch (17)

Proxy & adapter pattern
Proxy & adapter patternProxy & adapter pattern
Proxy & adapter pattern
 
Design Patterns Part1
Design Patterns  Part1Design Patterns  Part1
Design Patterns Part1
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
Design patterns - Adapter Pattern
Design patterns - Adapter PatternDesign patterns - Adapter Pattern
Design patterns - Adapter Pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Design Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade PatternDesign Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade Pattern
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Design pattern tutorial
Design pattern tutorialDesign pattern tutorial
Design pattern tutorial
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
 

Ähnlich wie Adapter design-pattern2015

Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
Amit Thakkar
 
Contributing to Drupal
Contributing to DrupalContributing to Drupal
Contributing to Drupal
Chris Skene
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentation
Vipul Divyanshu
 
Drupal Aware Design: Good Techniques for Better Themes
Drupal Aware Design: Good Techniques for Better ThemesDrupal Aware Design: Good Techniques for Better Themes
Drupal Aware Design: Good Techniques for Better Themes
nyccamp
 
Some Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and PrinciplesSome Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and Principles
itsarsalan
 

Ähnlich wie Adapter design-pattern2015 (20)

Building API's
Building API'sBuilding API's
Building API's
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
 
Contributing to Drupal
Contributing to DrupalContributing to Drupal
Contributing to Drupal
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Become a better UX designer through code
Become a better UX designer through codeBecome a better UX designer through code
Become a better UX designer through code
 
Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
 
Software Development with PHP & Laravel
Software Development  with PHP & LaravelSoftware Development  with PHP & Laravel
Software Development with PHP & Laravel
 
Design patterns
Design patternsDesign patterns
Design patterns
 
The Why and What of Pattern Lab
The Why and What of Pattern LabThe Why and What of Pattern Lab
The Why and What of Pattern Lab
 
30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer30 Skills to Master to Become a Senior Software Engineer
30 Skills to Master to Become a Senior Software Engineer
 
Vipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentationVipul divyanshu mahout_documentation
Vipul divyanshu mahout_documentation
 
Drupal Aware Design: Good Techniques for Better Themes
Drupal Aware Design: Good Techniques for Better ThemesDrupal Aware Design: Good Techniques for Better Themes
Drupal Aware Design: Good Techniques for Better Themes
 
ContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native DeveloperContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native Developer
 
The Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices CatalogueThe Drupal 7 Worst Practices Catalogue
The Drupal 7 Worst Practices Catalogue
 
Open agile is free and open source community agile-
Open agile  is free and open source community agile-Open agile  is free and open source community agile-
Open agile is free and open source community agile-
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
 
Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7
 
Contributing to drupal
Contributing to drupalContributing to drupal
Contributing to drupal
 
Some Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and PrinciplesSome Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and Principles
 

Kürzlich hochgeladen

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Kürzlich hochgeladen (20)

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

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 >
  • 2. OOP Design Patterns Links Drupal.org: VicOnt, nafes Presentation Code: https://www.drupal.org/project/oop_design_patterns https://www.drupal.org/project/oop_examples < 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 >
  • 12. OOP Design Patterns The Problem: multiple Payment Providers < https://www.drupal.org/project/oop_design_patterns >
  • 13. OOP Design Patterns The Solution: Adapter/Wrapper for Providers 1, 3 < https://www.drupal.org/project/oop_design_patterns > Scope res op
  • 14. OOP Design Patterns The Solution: Adapter/Wrapper for Provider 2 < https://www.drupal.org/project/oop_design_patterns >
  • 15. OOP Design Patterns Adapter Pattern: UML diagram, programming to the interface < https://www.drupal.org/project/oop_design_patterns >
  • 16. OOP Design Patterns Adapter Pattern: Easy of use, programming to the interface
  • 17. OOP Design Patterns Adapter Pattern: Drupal 7 implementation < https://www.drupal.org/project/oop_design_patterns >
  • 18. OOP Design Patterns Adapter Pattern: Drupal 8 implementation < https://www.drupal.org/project/oop_design_patterns >
  • 19. OOP Design Patterns CodeCase in action: < https://www.drupal.org/project/oop_design_patterns >
  • 20. OOP Design Patterns CodeCase in action: < 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 >