SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
Conscious Decoupling
Building Software that Lasts
Ciaran McNulty at Lone Star PHP 2016
Me
Hi, I'm Ciaran and I'm a PHP developer
I am a consultant with Inviqa
I maintain PhpSpec and contribute to Behat
My early period: Write procedural
code!
My middle period: Decouple all the
things!
My late period: Decouple some of the
things!
What is coupling?
class TaxiDispatcher {
function dispatch (Car $car, $destination)
{
$this->chargeCustomer();
$car->goTo($destination);
}
}
Problems with dependencies
4 Changes to Car mean changes to Dispatcher
4 Can't reuse Dispatcher with new vehicles
interface Vehicle
{
public function goTo($destination);
}
class TaxiDispatcher {
function dispatch (Vehicle $vehicle, $destination)
{
$this->chargeCustomer();
$vehicle->goTo($destination);
}
}
Benefits of abstraction
4 Now we only need to rewrite Dispatcher and Car
when Vehicle changes
4 Vehicle can be very stable; it's just an interface
4 Can make new transportation types that implement
Vehicle
Defining abstractions
4 Start with the abstraction, not the detail
4 Contract should be a simple as possible
4 Contract should focus on resposibilities
4 Hide details of underlying APIs
Example - upgrade eligibility
Bad abstraction:
interface HttpClient
{
public function getData : array ($url, $parameters);
}
Example - upgrade eligibility
Better abstraction:
interface UpgradeEligibilityChecker
{
public function getContractId : int ($phoneNumber);
public function isEligibleForUpgrade : bool ($contractId);
}
Example - upgrade eligibility
Best abstraction:
interface UpgradeEligibilityChecker
{
public function isEligibleForUpgrade : bool ($phoneNumber);
}
Or, get on the bus
4 Migrate actions from method calls to objects
4 Depend on a bus rather than depending on contracts
4 Don't know anything about what handles the action
Events
Direct coupling:
$notifier->notifyLawyersAboutPurchase($id, $item, $cost);
Event style:
$eventBus->dispatch(
new ItemWasPurchased($id, $item, $cost);
);
Commands
Use case / service style:
$invoiceApprover->approveInvoice(1234);
Command style:
$commandBus->dispatch(
new ApproveInvoice(1234);
);
Advantages of decoupling via
abstractions
4 Cleaner APIs
4 Swappable components
4 Separation of concerns
4 Easier to test
4 No 'ripple effect' around changes
Disadvantages of decoupling via
abstractions
4 Makes execution flow harder to follow
4 Adds more complexity (more files in codebase)
4 Cognitive cost of thinking of good abstractions
Architectural boundaries
4 Abstractions are going to change when the use cases
change
4 Interfaces are more tightly coupled to code that
uses them
4 Interfaces 'belong' in the same architectural
boundary as the code that uses them.
Frameworks
Coupling to other people's code
Highly coupled frameworks
Some frameworks let you go really quickly by coupling
directly to them.
You probably won't be able to reuse your code without
considerable effort.
4 Drupal
4 Magento
4 Wordpress
More coupled framworks
Some frameworks let you go faster when you adopt their
conventions.
You can reuse your code with a fair amount of additional
effort.
4 Laravel
4 Symfony1
4 CakePHP
More decoupled frameworks
Some frameworks encourage decoupling so your code is
more reusable.
You will go a little slower because you need to explicitly
configure things
4 Symfony 2
4 Zend Framework 2
Very decoupled frameworks
Some frameworks are extremely decoupled so code is
almost entirely reusable.
You almost have to construct the entire framework
yourself from components - this can be hard!
4 D.I.Y.
4 Zend Expressive
Only decouple where you
need to
(wait, how do we know where that is?)
Coupled code get painful
when change happens
Decoupled code was
wasted effort when change
doesn't happen
Where does change come
from?
Where does change come from?
People!
Decouple your system to
respond to different
streams of change
Organizations which design
systems ... are constrained to
produce designs which are copies
of the communication structures
of these organizations
1
Melvin Conway, 1967
Context mapping
4 Identify subdomains
4 Identify which are:
4 Core subdomains
4 Supporting subdomains
4 Generic subdomains
4 Mirror the structure in your architecture
The bad news:
You will get it wrong
You only find out afterwards
The good news:
It's not just you
Things to check out
4 Context Mapping
4 Hexagonal Architecture
4 Modelling by Example
Thank you!
4 @ciaranmcnulty
4 Lead Maintainer of PhpSpec
4 SeniorTrainer at Inviqa
4 https://joind.in/talk/e20e3
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 

Was ist angesagt? (18)

10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Prersentation
PrersentationPrersentation
Prersentation
 
vb script
vb scriptvb script
vb script
 
Web development basics (Part-6)
Web development basics (Part-6)Web development basics (Part-6)
Web development basics (Part-6)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript Essentials for Ember development
JavaScript Essentials for Ember developmentJavaScript Essentials for Ember development
JavaScript Essentials for Ember development
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
php app development 1
php app development 1php app development 1
php app development 1
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 

Andere mochten auch

Public health certificate
Public health certificatePublic health certificate
Public health certificate
Monica McDaniel
 
Buscar imágenes en la web
Buscar imágenes en la web Buscar imágenes en la web
Buscar imágenes en la web
TICS & Partners
 
Diseño de una guía didáctica con imágenes
Diseño de una guía didáctica con imágenesDiseño de una guía didáctica con imágenes
Diseño de una guía didáctica con imágenes
TICS & Partners
 
Tutorial: cómo cargar un video a Edmodo desde Youtube
Tutorial: cómo cargar un video a Edmodo desde YoutubeTutorial: cómo cargar un video a Edmodo desde Youtube
Tutorial: cómo cargar un video a Edmodo desde Youtube
TICS & Partners
 

Andere mochten auch (18)

Administracion
AdministracionAdministracion
Administracion
 
Public health certificate
Public health certificatePublic health certificate
Public health certificate
 
Buscar imágenes en la web
Buscar imágenes en la web Buscar imágenes en la web
Buscar imágenes en la web
 
How Can I Convert PIO Card into OCI Card?
How Can I Convert PIO Card into OCI Card?How Can I Convert PIO Card into OCI Card?
How Can I Convert PIO Card into OCI Card?
 
Diseño de una guía didáctica con imágenes
Diseño de una guía didáctica con imágenesDiseño de una guía didáctica con imágenes
Diseño de una guía didáctica con imágenes
 
Վեբ 2.0՝ ի՞նչ է դա
Վեբ 2.0՝ ի՞նչ է դաՎեբ 2.0՝ ի՞նչ է դա
Վեբ 2.0՝ ի՞նչ է դա
 
First aid certificate 2016
First aid certificate 2016First aid certificate 2016
First aid certificate 2016
 
Social Media for the Federation of Small Businesses
Social Media for the Federation of Small BusinessesSocial Media for the Federation of Small Businesses
Social Media for the Federation of Small Businesses
 
Merbromin 129-16-8-api
Merbromin 129-16-8-apiMerbromin 129-16-8-api
Merbromin 129-16-8-api
 
PHP Conference 2016
PHP Conference 2016PHP Conference 2016
PHP Conference 2016
 
WordCamp SP 2016
WordCamp SP 2016WordCamp SP 2016
WordCamp SP 2016
 
Tutorial: cómo cargar un video a Edmodo desde Youtube
Tutorial: cómo cargar un video a Edmodo desde YoutubeTutorial: cómo cargar un video a Edmodo desde Youtube
Tutorial: cómo cargar un video a Edmodo desde Youtube
 
Recommendation for Maya Emilova
Recommendation for Maya EmilovaRecommendation for Maya Emilova
Recommendation for Maya Emilova
 
Canada Mortgage and Housing Corporation's (CMHC) Municipal Infrastructure Len...
Canada Mortgage and Housing Corporation's (CMHC) Municipal Infrastructure Len...Canada Mortgage and Housing Corporation's (CMHC) Municipal Infrastructure Len...
Canada Mortgage and Housing Corporation's (CMHC) Municipal Infrastructure Len...
 
Performance-Analyse mit Bordmitteln
Performance-Analyse mit BordmittelnPerformance-Analyse mit Bordmitteln
Performance-Analyse mit Bordmitteln
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
 
The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)
 
"let ECMAScript = 6"
"let ECMAScript = 6" "let ECMAScript = 6"
"let ECMAScript = 6"
 

Ähnlich wie Conscious Decoupling - Lone Star PHP

2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
PHP Conference Argentina
 

Ähnlich wie Conscious Decoupling - Lone Star PHP (20)

Conscious Coupling
Conscious CouplingConscious Coupling
Conscious Coupling
 
Functional programming is not about complicated things
Functional programming is not about complicated thingsFunctional programming is not about complicated things
Functional programming is not about complicated things
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Node.JS Vs PHP: Which Is The Top Server-Side Programming Language?
Node.JS Vs PHP: Which Is The Top Server-Side Programming Language?Node.JS Vs PHP: Which Is The Top Server-Side Programming Language?
Node.JS Vs PHP: Which Is The Top Server-Side Programming Language?
 
Outsourcing php india
Outsourcing php indiaOutsourcing php india
Outsourcing php india
 
Unleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ PlatformUnleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ Platform
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Applied progressive decoupling weather.com, angular, and drupal
Applied progressive decoupling  weather.com, angular, and drupalApplied progressive decoupling  weather.com, angular, and drupal
Applied progressive decoupling weather.com, angular, and drupal
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
ContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native DeveloperContainerDayVietnam2016: Become a Cloud-native Developer
ContainerDayVietnam2016: Become a Cloud-native Developer
 
Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?
 
Top 5 advanced php framework in 2018
Top 5 advanced php framework in 2018Top 5 advanced php framework in 2018
Top 5 advanced php framework in 2018
 
Introducing symfony
Introducing symfonyIntroducing symfony
Introducing symfony
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
Top 10 php frameworks in 2021
Top 10 php frameworks in 2021Top 10 php frameworks in 2021
Top 10 php frameworks in 2021
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0
 

Mehr von CiaranMcNulty

Mehr von CiaranMcNulty (16)

Greener web development at PHP London
Greener web development at PHP LondonGreener web development at PHP London
Greener web development at PHP London
 
Doodle Driven Development
Doodle Driven DevelopmentDoodle Driven Development
Doodle Driven Development
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
 
Behat Best Practices
Behat Best PracticesBehat Best Practices
Behat Best Practices
 
Behat Best Practices with Symfony
Behat Best Practices with SymfonyBehat Best Practices with Symfony
Behat Best Practices with Symfony
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
 
Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016Modelling by Example Workshop - PHPNW 2016
Modelling by Example Workshop - PHPNW 2016
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the Job
 
Fly In Style (without splashing out)
Fly In Style (without splashing out)Fly In Style (without splashing out)
Fly In Style (without splashing out)
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015Driving Design through Examples - PhpCon PL 2015
Driving Design through Examples - PhpCon PL 2015
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
 
Driving Design through Examples
Driving Design through ExamplesDriving Design through Examples
Driving Design through Examples
 
Why Your Test Suite Sucks
Why Your Test Suite SucksWhy Your Test Suite Sucks
Why Your Test Suite Sucks
 
Using HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless IntegrationUsing HttpKernelInterface for Painless Integration
Using HttpKernelInterface for Painless Integration
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
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
 

Kürzlich hochgeladen (20)

%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
 
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...
 
%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
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
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
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+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...
 

Conscious Decoupling - Lone Star PHP

  • 1. Conscious Decoupling Building Software that Lasts Ciaran McNulty at Lone Star PHP 2016
  • 2. Me Hi, I'm Ciaran and I'm a PHP developer I am a consultant with Inviqa I maintain PhpSpec and contribute to Behat
  • 3. My early period: Write procedural code!
  • 4. My middle period: Decouple all the things!
  • 5. My late period: Decouple some of the things!
  • 7. class TaxiDispatcher { function dispatch (Car $car, $destination) { $this->chargeCustomer(); $car->goTo($destination); } }
  • 8.
  • 9.
  • 10.
  • 11. Problems with dependencies 4 Changes to Car mean changes to Dispatcher 4 Can't reuse Dispatcher with new vehicles
  • 12. interface Vehicle { public function goTo($destination); } class TaxiDispatcher { function dispatch (Vehicle $vehicle, $destination) { $this->chargeCustomer(); $vehicle->goTo($destination); } }
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. Benefits of abstraction 4 Now we only need to rewrite Dispatcher and Car when Vehicle changes 4 Vehicle can be very stable; it's just an interface 4 Can make new transportation types that implement Vehicle
  • 18. Defining abstractions 4 Start with the abstraction, not the detail 4 Contract should be a simple as possible 4 Contract should focus on resposibilities 4 Hide details of underlying APIs
  • 19. Example - upgrade eligibility Bad abstraction: interface HttpClient { public function getData : array ($url, $parameters); }
  • 20. Example - upgrade eligibility Better abstraction: interface UpgradeEligibilityChecker { public function getContractId : int ($phoneNumber); public function isEligibleForUpgrade : bool ($contractId); }
  • 21. Example - upgrade eligibility Best abstraction: interface UpgradeEligibilityChecker { public function isEligibleForUpgrade : bool ($phoneNumber); }
  • 22. Or, get on the bus 4 Migrate actions from method calls to objects 4 Depend on a bus rather than depending on contracts 4 Don't know anything about what handles the action
  • 23. Events Direct coupling: $notifier->notifyLawyersAboutPurchase($id, $item, $cost); Event style: $eventBus->dispatch( new ItemWasPurchased($id, $item, $cost); );
  • 24. Commands Use case / service style: $invoiceApprover->approveInvoice(1234); Command style: $commandBus->dispatch( new ApproveInvoice(1234); );
  • 25. Advantages of decoupling via abstractions 4 Cleaner APIs 4 Swappable components 4 Separation of concerns 4 Easier to test 4 No 'ripple effect' around changes
  • 26. Disadvantages of decoupling via abstractions 4 Makes execution flow harder to follow 4 Adds more complexity (more files in codebase) 4 Cognitive cost of thinking of good abstractions
  • 27. Architectural boundaries 4 Abstractions are going to change when the use cases change 4 Interfaces are more tightly coupled to code that uses them 4 Interfaces 'belong' in the same architectural boundary as the code that uses them.
  • 28.
  • 29.
  • 30.
  • 32. Highly coupled frameworks Some frameworks let you go really quickly by coupling directly to them. You probably won't be able to reuse your code without considerable effort. 4 Drupal 4 Magento 4 Wordpress
  • 33. More coupled framworks Some frameworks let you go faster when you adopt their conventions. You can reuse your code with a fair amount of additional effort. 4 Laravel 4 Symfony1 4 CakePHP
  • 34. More decoupled frameworks Some frameworks encourage decoupling so your code is more reusable. You will go a little slower because you need to explicitly configure things 4 Symfony 2 4 Zend Framework 2
  • 35. Very decoupled frameworks Some frameworks are extremely decoupled so code is almost entirely reusable. You almost have to construct the entire framework yourself from components - this can be hard! 4 D.I.Y. 4 Zend Expressive
  • 36. Only decouple where you need to (wait, how do we know where that is?)
  • 37. Coupled code get painful when change happens Decoupled code was wasted effort when change doesn't happen
  • 38. Where does change come from?
  • 39. Where does change come from? People!
  • 40.
  • 41.
  • 42.
  • 43.
  • 44. Decouple your system to respond to different streams of change
  • 45.
  • 46.
  • 47. Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations 1 Melvin Conway, 1967
  • 48. Context mapping 4 Identify subdomains 4 Identify which are: 4 Core subdomains 4 Supporting subdomains 4 Generic subdomains 4 Mirror the structure in your architecture
  • 49. The bad news: You will get it wrong You only find out afterwards
  • 50. The good news: It's not just you
  • 51. Things to check out 4 Context Mapping 4 Hexagonal Architecture 4 Modelling by Example
  • 52. Thank you! 4 @ciaranmcnulty 4 Lead Maintainer of PhpSpec 4 SeniorTrainer at Inviqa 4 https://joind.in/talk/e20e3 Questions?