SlideShare a Scribd company logo
Conscious Coupling
Building Software that Lasts
Ciaran McNulty at SymfonyLive London
Me
Hi, I'm Ciaran and I'm a PHP developer
I am a consultant with Inviqa
I maintain PhpSpec
My early period:
Follow the framework!
SymfonyLive London 2013
Konstantin Kudryashov and Marcello Duarte -
The Framework as an Implementation Detail
SymfonyLive London 2014
Matthias Noback - The Naked Bundle
My middle period:
Decouple all the things!
Modelling by Example
Konstantin Kudryashov (again)
My current period:
Couple some of the things!
What is coupling?
class TaxiDispatcher {
function dispatch (Car $car, $destination)
{
$this->chargeCustomer();
$car->goTo($destination);
}
}
Conscious Coupling
Conscious Coupling
Conscious Coupling
Problems with dependencies
—Changes to Car mean changes to Dispatcher
—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);
}
}
Conscious Coupling
Conscious Coupling
Conscious Coupling
Conscious Coupling
Benefits of abstraction
—Now we only need to rewrite Dispatcher and Car
when Vehicle changes
—Vehicle can be very stable; it's just an interface
—Can make new transportation types that
implement Vehicle
Defining abstractions
—Start with the use case, not the implementation
detail
—Contract should be a simple as possible
—Contract should focus on responsibilities
—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);
}
Abstraction via interfaces
—You still need to know what methods to call
—Caller has to respond to changes in the callee
Taking it further:
Events and Commands
—Migrate actions from method calls to objects
—Depend on a bus rather than depending on
contracts
—Don't know anything about what handles the
action
Events
Direct coupling:
$notifier->notifyLawyersAboutPurchase($id, $item, $cost);
Event style (symfony/event-dispatcher):
$eventDispatcher->dispatch(
'item.purchased',
new ItemWasPurchased($id, $item, $cost);
);
Commands
Use case / service style:
$invoiceApprover->approveInvoice(1234);
Command style (thephpleague/tactician):
$commandBus->handle(
new ApproveInvoice(1234);
);
Advantages of decoupling via abstractions
—Cleaner APIs
—Swappable components
—Separation of concerns
—Easier to test
—No 'ripple effect' around changes
Disadvantages of decoupling via abstractions
—Makes execution flow harder to follow
—Adds more complexity (more files in codebase)
—Cognitive cost of thinking of good abstractions
Decoupling from
infrastructure
—Abstractions are going to change when the use
cases change
—Interfaces are more tightly coupled to code that
uses them
—Interfaces 'belong' in the same architectural
boundary as the code that uses them.
Conscious Coupling
Conscious Coupling
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.
—Drupal
—Magento
—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.
—Symfony (1)
—CakePHP
—Laravel
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
—Symfony 2+
—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!
—D.I.Y.
—Silex
—Zend Expressive
Decoupling inside your
system
Only decouple where you
need to
(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!
Organizations which design
systems ... are constrained
to produce designs which
are copies of the
communication structures of
these organizations
— Melvin Conway, 1967
Conscious Coupling
Conscious Coupling
Conscious Coupling
Conscious Coupling
Decouple your system to
respond to different
streams of change
Conscious Coupling
Conscious Coupling
Service-orientation
—Good abstractions help you define boundaries
—Abstractions inside a monolith are easier to move
when you get it wrong
—Share values, not entities
—Don't share persistence
Conscious Coupling
Context mapping
—Identify subdomains
—Identify which are:
—Core subdomains
—Supporting subdomains
—Generic subdomains
—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
—Context Mapping
—Hexagonal Architecture
—Modelling by Example
Thank you!
—@ciaranmcnulty
—Lead Maintainer of PhpSpec
—Trainer and Coach at Inviqa
Questions?

More Related Content

PDF
eZ Publish Platform 5.4 public webinar
PDF
BASICS OF VERT.X - A toolkit for building asynchronous and reactive app
PDF
WASM! WASI! WAGI! WAT?
PDF
Super combinators
PDF
DIY Async Message Pump: Lessons from the trenches
PDF
Symfony finally swiped right on envvars
PPTX
Data Management and Streaming Strategies in Drakensang Online
PDF
Learnings from Real eZ Publish 5 Projects
eZ Publish Platform 5.4 public webinar
BASICS OF VERT.X - A toolkit for building asynchronous and reactive app
WASM! WASI! WAGI! WAT?
Super combinators
DIY Async Message Pump: Lessons from the trenches
Symfony finally swiped right on envvars
Data Management and Streaming Strategies in Drakensang Online
Learnings from Real eZ Publish 5 Projects

What's hot (20)

PPTX
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
PPSX
Webpack & EcmaScript 6 (Webelement #32)
PDF
Serverless Rust
PDF
Productive web applications that run only on the frontend
PDF
WebAssemlby vs JavaScript
PPTX
Creating Perl modules with Dist::Zilla
PPTX
Docker in 30 minutes
PDF
Fix: static code analysis into our project
PPTX
C++ on the Web: Run your big 3D game in the browser
PPTX
Android kotlin coroutines
ODP
PHP: The Beginning and the Zend
PDF
Web performances : Is It not the right time to (re)consider CMS ?
PPTX
What's New in ASP.NET Core 2.0
PDF
Minko - Build WebGL applications with C++ and asm.js
PDF
Communication in Python and the C10k problem
PDF
How to deploy PHP projects with docker
PDF
Dist::Zilla - A very brief introduction
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
PPT
Building dynamic websites with Mod perl and apache
PPTX
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Webpack & EcmaScript 6 (Webelement #32)
Serverless Rust
Productive web applications that run only on the frontend
WebAssemlby vs JavaScript
Creating Perl modules with Dist::Zilla
Docker in 30 minutes
Fix: static code analysis into our project
C++ on the Web: Run your big 3D game in the browser
Android kotlin coroutines
PHP: The Beginning and the Zend
Web performances : Is It not the right time to (re)consider CMS ?
What's New in ASP.NET Core 2.0
Minko - Build WebGL applications with C++ and asm.js
Communication in Python and the C10k problem
How to deploy PHP projects with docker
Dist::Zilla - A very brief introduction
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Building dynamic websites with Mod perl and apache
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Ad

Viewers also liked (20)

PDF
Modelling by Example Workshop - PHPNW 2016
PDF
Driving Design through Examples
PDF
Presentation Bulgaria PHP
PDF
How I started to love design patterns
PDF
php[world] 2015 Training - Laravel from the Ground Up
PDF
Zend Framework Foundations
PDF
Amp your site an intro to accelerated mobile pages
PPTX
Engineer - Mastering the Art of Software
PDF
Hack the Future
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
PDF
Create, test, secure, repeat
PDF
Dip Your Toes in the Sea of Security
PDF
Git Empowered
PDF
Code Coverage for Total Security in Application Migrations
PDF
Console Apps: php artisan forthe:win
PPTX
Php extensions
PDF
SunshinePHP 2017 - Making the most out of MySQL
PPTX
Modern sql
PDF
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PDF
Intermediate OOP in PHP
Modelling by Example Workshop - PHPNW 2016
Driving Design through Examples
Presentation Bulgaria PHP
How I started to love design patterns
php[world] 2015 Training - Laravel from the Ground Up
Zend Framework Foundations
Amp your site an intro to accelerated mobile pages
Engineer - Mastering the Art of Software
Hack the Future
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Create, test, secure, repeat
Dip Your Toes in the Sea of Security
Git Empowered
Code Coverage for Total Security in Application Migrations
Console Apps: php artisan forthe:win
Php extensions
SunshinePHP 2017 - Making the most out of MySQL
Modern sql
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
Intermediate OOP in PHP
Ad

Similar to Conscious Coupling (20)

PDF
Conscious Decoupling - Lone Star PHP
PDF
Microservices. Microservices everywhere! (At OSCON 2015)
PDF
Containerizing legacy applications
PDF
A Shift from Monolith to Microservice using Docker
PPTX
Problems you’ll face in the Microservices World: Configuration, Authenticatio...
PDF
Beginning MEAN Stack
PDF
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
PDF
3-Way Scripts as a Practical Platform for Secure Distributed Code in Clouds
PPT
Net remoting
PPTX
React hooks
PDF
OSGi Cloud Ecosystems - David Bosschaert
PPT
DCI with groovy
PDF
L03 Software Design
PDF
OSGi and Cloud Computing - David Bosschaert
PDF
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
PDF
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
PPT
Node js
PPTX
Nodejs overview
PPTX
Cloud hybridation leveraging on Docker 1.12
PDF
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Conscious Decoupling - Lone Star PHP
Microservices. Microservices everywhere! (At OSCON 2015)
Containerizing legacy applications
A Shift from Monolith to Microservice using Docker
Problems you’ll face in the Microservices World: Configuration, Authenticatio...
Beginning MEAN Stack
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
3-Way Scripts as a Practical Platform for Secure Distributed Code in Clouds
Net remoting
React hooks
OSGi Cloud Ecosystems - David Bosschaert
DCI with groovy
L03 Software Design
OSGi and Cloud Computing - David Bosschaert
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (Symfony Live Berli...
Node js
Nodejs overview
Cloud hybridation leveraging on Docker 1.12
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)

More from CiaranMcNulty (17)

PDF
Greener web development at PHP London
PDF
Doodle Driven Development
PDF
Behat Best Practices with Symfony
PDF
Behat Best Practices
PDF
Behat Best Practices with Symfony
PDF
Driving Design through Examples
PDF
Finding the Right Testing Tool for the Job
PDF
TDD with PhpSpec - Lone Star PHP 2016
PDF
Fly In Style (without splashing out)
PDF
Why Your Test Suite Sucks - PHPCon PL 2015
PDF
Driving Design through Examples - PhpCon PL 2015
PDF
Building a Pyramid: Symfony Testing Strategies
PDF
TDD with PhpSpec
PDF
Driving Design through Examples
PDF
Why Your Test Suite Sucks
PDF
Driving Design with PhpSpec
PDF
Using HttpKernelInterface for Painless Integration
Greener web development at PHP London
Doodle Driven Development
Behat Best Practices with Symfony
Behat Best Practices
Behat Best Practices with Symfony
Driving Design through Examples
Finding the Right Testing Tool for the Job
TDD with PhpSpec - Lone Star PHP 2016
Fly In Style (without splashing out)
Why Your Test Suite Sucks - PHPCon PL 2015
Driving Design through Examples - PhpCon PL 2015
Building a Pyramid: Symfony Testing Strategies
TDD with PhpSpec
Driving Design through Examples
Why Your Test Suite Sucks
Driving Design with PhpSpec
Using HttpKernelInterface for Painless Integration

Recently uploaded (20)

PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Strategies for Manufacturing Companies
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
history of c programming in notes for students .pptx
PDF
System and Network Administraation Chapter 3
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How to Choose the Right IT Partner for Your Business in Malaysia
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
history of c programming in notes for students .pptx
System and Network Administraation Chapter 3
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Online Work Permit System for Fast Permit Processing
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

Conscious Coupling