SlideShare a Scribd company logo
1 of 131
Download to read offline
Functional Soλid
     Matt Stine
About your speaker...
•   Senior Consultant, PSO
    vFabric, Cloud Application Platform
    VMware

•   Speaker (JavaOne, SpringOne/2GX,
    CodeMash, NFJS, RWX, PAX, UberConf)

•   Author (GroovyMag, NFJS the Magazine,
    Selenium 2.0 Refcard)

•   Founder of the Memphis/Mid-South Java
    User Group

•   Former Agile Zone Leader @ DZone
SOLID        Functional
Principles   Programming
SOLID Functional
PrinciplesProgramming
Pitch

• Software designs tend to rot.
• Design rot impedes our effectiveness.
• SOLID principles help treat design rot.
• Achieving SOLID designs is another
  reason to learn FP!
Motivation
Trends

• How Software Systems Evolve
• Programming Paradigms
• The Quest for “Best Practices”
The evolution of
  software...
http://www.flickr.com/photos/billselak/427719926




                                                  http://www.flickr.com/photos/unloveable/2400895854



          From simplicity to complexity...
http://www.flickr.com/photos/thejcgerm/379082415




                                                  Software starts
                                                    to rot like a
                                                   bad piece of
                                                       meat.

                                                   “Uncle Bob”
                                                     Martin
We don’t handle
 change well...
Unclear or incomplete
change specifications...
Extreme time
 pressure...
Team members
unfamiliar with original
 design/architecture...
It smells!
Rigidity
Fragility
Immobility
Viscosity
Needless Complexity
Needless Repetition
Opacity
Programming
 Paradigms
Programming eras...

• Structured Programming
  (late 1960’s - late 1980’s)
• Object Oriented Programming
  (mid 1970’s - present day)
• Functional Programming
  (early 1990’s - ???)
THE CHASM
Accumulation of
 Knowledge?
Accumulation of
 Knowledge?
Paradigm Shifts
http://www.gotw.ca/publications/concurrency-ddj.htm
The Quest
      for
“Best Practices”
• Which web framework should I use?
• Why are there so many persistence API’s?
• Which is better: Scala or Clojure (or
  Erlang)?

• How should I use design patterns?
• How do I build a good architecture?
http://en.wikipedia.org/wiki/No_Silver_Bullet
What are the FP best
    practices?
The Perfect Storm
SRP   OCP        LSP

             The
           SOLID
ISP   DIP Principles
http://clojure.org
http://www.infoq.com/presentations/SOLID-Clojure
The Single
Responsibility Principle
A class (module) should
 have only one reason
       to change.
COHESION




Tom DeMarco   Meilir Page-Jones
Computational      Rectangle
                                     Graphical
 Geometry       + draw()            Application
 Application    + area() : double




                      GUI
Computational
                       Graphical
  Geometry
                      Application
  Application




   Geometric           Rectangle
   Rectangle
                                    GUI
                    + draw()
+ area() : double
Metaresponsibilities of
   an OO class...

• Model state
• Model behavior
State

•   car.color = black
•   elevator.floor = 10
•   account.balance = 2500
Behavior

•   car.drive()
•   elevator.climb()
•   account.deposit(500)
How many
metaresponsibilities?
It is better to have 100 functions operate on one
data structure than to have 10 functions operate
               on 10 data structures.

                  Alan J. Perlis
Metaresponsibilities of
   an OO class...

• Model state
• Model behavior
• Model identity
IDENTITY

car1 != car2

   VALUE

car1 == car2
Concurrent System

• Automated “Needs Service” Notification
  System
• Thread 1: Update mileage and “ready for
  service indicators”
• Thread 2: Harvest cars ready for service
  and send notifications
The Open Closed
    Principle
Bertrand Myer
Software entities should
be open for extension but
 closed for modification.
Open for extension...
...closed for
modification.
Abstraction!

• Java:
 • interface
 • abstract class
(pause OCP)
Let’s do design!

• OO language (Java)
• We want to use the OCP
• We’ll create one or more inheritance
  hierarchies!
• Well...
Inheritance
          Hierarchies?

• What do good ones look like?
• Are there rules we can follow (best
  practices even)?
• Are there traps we can fall in to?
The Liskov
                 Substitution Principle




Barbara Liskov
What is wanted here is something like the following
substitution property: If for each object o1 of type S there is
 an object o2 of type T such that for all programs P defined
  in terms of T, the behavior of P is unchanged when o1 is
         substituted for o2, then S is a subtype of T.
Subtypes must be
substitutable for their
     base types.
f(B b) { }
D extends B
B d = new D();
     f(d)
f(B b) {
	 if (b instance of D) {
	 	 //deal with D
	 } else {
	 	 //continue as before
	}
}
(resume OCP)
Composition
 The Functional OCP
First-class Functions
Higher-order Functions
The Interface
Segregation Principle
Clients should not be
  forced to depend on
methods they do not use.
<<interface>>
                  TimerClient
Timer
        0..*
               + timeout()




                     Door




                  TimedDoor
<<interface>>
                  TimerClient
Timer                                               Door
        0..*
               + timeout()




               DoorTimerAdapter                    TimedDoor

               + timeout()                      + doorTimeOut()


                                  <<creates>>
<<interface>>
           TimerClient
Timer                                    Door
        + timeout()




                             TimedDoor

                          + timeout()
Thinking in Verbs
Verbs

• Open
• Close
• Register Timeout
• Trigger Timeout
OK...what about that
unique ID problem?
The Dependency
Inversion Principle
Abstractions should not
depend upon details. Details
   should depend upon
       abstractions.
High-level modules
should not depend on
  low-level modules.
Policy Layer


               Mechanism
                 Layer


                           Utility Layer
<<interface>>
Policy Layer   Policy Service
                 Interface




                                 <<interface>>
                Mechanism
                                  Mechanism
                  Layer
                                Service Interface




                                  Utility Layer
Our verbs have been
       taken captive by
            nouns...

http://steve-yegge.blogspot.com/2006/03/execution-in-
                kingdom-of-nouns.html
http://www.infoq.com/presentations/Simple-Made-Easy/
Complectedness
SRP

Complecting responsibilities leads
  to rigid and/or fragile design.
OCP
            Problematic:
  Complecting concretions of an
abstraction in such a way that new
   concretions adversely affect
  existing, working concretions.
LSP
  Reuse via inheritance is
dangerous. Often complects
 entities not in a true “is-a”
 relationship. Leads to non-
        substitutability.
ISP


 Don’t complect unrelated
operations in a single entity!
DIP


Transitive dependency leads to
  transitive complectedness!
Design is the art of breaking
        things apart.

       - Rich Hickey
Matt Stine
         matt.stine@gmail.com
             Twitter: mstine
       http://www.mattstine.com
Please fill out your evaluations!

More Related Content

What's hot

C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 

What's hot (20)

Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Function
FunctionFunction
Function
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
 

Similar to Functional solid

.NET Architecture for Enterprises
.NET Architecture for Enterprises.NET Architecture for Enterprises
.NET Architecture for Enterprises
Wade Wegner
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
jeffz
 

Similar to Functional solid (20)

Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
SDWest2005Goetsch
SDWest2005GoetschSDWest2005Goetsch
SDWest2005Goetsch
 
.NET Architecture for Enterprises
.NET Architecture for Enterprises.NET Architecture for Enterprises
.NET Architecture for Enterprises
 
Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)
 
Let's talk about... Microservices
Let's talk about... MicroservicesLet's talk about... Microservices
Let's talk about... Microservices
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices
 
How do we drive tech changes
How do we drive tech changesHow do we drive tech changes
How do we drive tech changes
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Illogical engineers
Illogical engineersIllogical engineers
Illogical engineers
 
Illogical engineers
Illogical engineersIllogical engineers
Illogical engineers
 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
04 managing the database
04   managing the database04   managing the database
04 managing the database
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 
Math with .NET for you and Azure
Math with .NET for you and AzureMath with .NET for you and Azure
Math with .NET for you and Azure
 

More from Matt Stine

Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesCloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
Matt Stine
 
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipCloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Matt Stine
 
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Matt Stine
 

More from Matt Stine (20)

Architectures That Bend but Don't Break
Architectures That Bend but Don't BreakArchitectures That Bend but Don't Break
Architectures That Bend but Don't Break
 
Cloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns TutorialCloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns Tutorial
 
Resilient Architecture
Resilient ArchitectureResilient Architecture
Resilient Architecture
 
Cloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run MicroservicesCloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run Microservices
 
Reactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaReactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJava
 
Lattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsLattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring Applications
 
The Cloud Native Journey
The Cloud Native JourneyThe Cloud Native Journey
The Cloud Native Journey
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and Beyond
 
Deploying Microservices to Cloud Foundry
Deploying Microservices to Cloud FoundryDeploying Microservices to Cloud Foundry
Deploying Microservices to Cloud Foundry
 
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesCloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring Cloud
 
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web ServicesPivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Agile Development with OSGi
Agile Development with OSGiAgile Development with OSGi
Agile Development with OSGi
 
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipCloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
 
It's the End of the Cloud as We Know It
It's the End of the Cloud as We Know ItIt's the End of the Cloud as We Know It
It's the End of the Cloud as We Know It
 
Vert.x
Vert.xVert.x
Vert.x
 
The Seven Wastes of Software Development
The Seven Wastes of Software DevelopmentThe Seven Wastes of Software Development
The Seven Wastes of Software Development
 
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
 
Achieve Your Goals
Achieve Your GoalsAchieve Your Goals
Achieve Your Goals
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Functional solid