SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
over
presentation

                                http
    business
     logic




problem 1:
presentation depends on the interaction
flow, and mobile flows are really
different
presentation



                                http
   business
    logic




                 presentation



                                http

problem 2:
conversation state shared between client
and server. conversation state on
server leads to “session abuse”
presentation



                                http
   business
    logic




                 presentation



                                http

problem 2:
conversation state shared between client
and server. conversation state on
server leads to “session abuse”
presentation



                                http
   business
    logic




                 presentation



                                http

problem 2:
conversation state shared between client
and server. conversation state on
server leads to “session abuse”
n
                                         io



                 presentation
                                       t



                                http
                                       a
                                      s e
   business
    logic                            r t
                                    e a
                                   v t
                 presentation
                                  n s

                                http
                 c              o

problem 2:
conversation state shared between client
and server. conversation state on
server leads to “session abuse”
n
                                          io



                  presentation
                                        t



                                 http
                                        a
ap                                     s e
  pl business
      logic
     ic                               r t
                                     e a
 st at
                                    v t
                  presentation
   at io                           n s

                                 http
       e n
                  c              o

problem 2:
 conversation state shared between client
 and server. conversation state on
 server leads to “session abuse”
n
                                                                io



                                        presentation
                                                              t



                                                       http
                                                              a
ap                                                           s e
  pl business
                                                            r t
                  presentation



                                 http




       business
        logic
                  presentation



                                 http




                                                           e a
      logic
     ic
 st at
                                                          v t
                                        presentation
   at io                                                 n s

                                                       http
       e n
                                        c              o

problem 2: (sessions)
 could make horizontal scalability harder
 than it should be
n
                                           io



                   presentation
                                         t



                                  http
                                         a
ap                                      s e
  pl business
      logic
     ic                                r t
                                      e a
 st at
                                     v t
                   presentation
   at io                            n s

                                  http
       e n
                  c               o

problem 2: (sessions)
 it’s very hard to migrate conversations
 from agents (mobile <-> desktop)
logic
                                                                 business



                                                   business                  business
                                                    logic                     logic
                                                    usage                     usage


                                                  presentation              presentation




                                     problem 3:
                                                    http                      http




business logic usage is duplicated
business
                                                                        logic




                                            problem 3:
                                                              business              business
                                                               logic                 logic




                                            (duplication)
                                                               usage                 usage


                                                            presentation          presentation


                                                                http                  http
worst when there’s an anemic domain model
presentation




               presentation



                              http
  business
   logic
                                                    presentation




               presentation



                              http




problem 4: rich client
more duplication (different languages),
more difficult to separate
responsibilities (where is what?)
presentation
              business




                                        http
               usage
               logic
 business
  logic




                         presentation
              business




                                        http
               usage
               logic




problem 5: (testability)
difficult to reach a particular point in
the conversation. presentation changes
often (smell: divergent change)
presentation




 business
  logic

            http
                                  presentation




adopted solution
SmartphoneClient.prototype.next = function() {
  var self = this
  this.seq(
     this.purchase,
     this.transferIn,
     this.optIn,
     this.waitForCompletion
  ).exit(function(exit) {
     exit.callHandler(self.callbacks)
  })
}

                        var client = new SmartphoneClient(server, {
                           onError: function(error) {
                              app.pages.notify.error(error)
                           },
                           onRoute: function(route) {
                              app.goTo(route)
                           },
                           onUrl: function(url) {
                              location.href = url
                           }
                        })
presentation




business
 logic

           http
                                 presentation




  clear separation
from application and
 conversation state
presentation




    business
     logic

               http
                                     presentation




  stateless: easy to scale
horizontally, conversations
  can be migrated/resumed
$app->post("/purchase/:id/transfer-in/opt-in/pin",
    function($purchaseId) use($app) {
        ContentDelivery::on($app)
            ->process(function($request, $response) use($purchaseId, $app) {
                $purchase = Purchase::fromRequest($request, $purchaseId);
                $transferIn = $purchase->boundedTransferIn("pin-flow");
                $transferIn->checkPin($request->params("pin"));

                $response->status(200);
            })
            ->rescue('OnebipCoreNotSupportedActionInState', 409)
            ->rescue('OnebipPurchasePurchaseNotFound', 404)
            ->rescue('OnebipPurchaseTransferInNotFound', 404)
            ->rescue('OnebipPurchaseSpendingLimitReached', 403)
            ->rescue('OnebipPurchaseCheckPinFailed', 400)
            ->rescue('HttpUnauthenticatedRequest', 401)
            ->deliver();
     }
);


                         look, no session,
                        and the controller
                        code is really small
presentation




   business
    logic

              http
                                    presentation




clear application interface
$app->map("/purchases", ...
$app->get("/purchase/:id", ...
$app->post("/purchase/:id/login", ...
$app->get("/purchase/:id/buyer", ...
$app->post("/purchase/:id/transfers-in", ...
$app->get("/purchase/:id/transfer-in", ...
$app->put("/purchase/:id/transfer-in", ...
$app->post("/purchase/:id/transfer-in/opt-in/pin", ...
$app->put("/purchase/:id/transfer-in/mo", ...




                      clear application
                          interface
presentation




business
 logic

           http
                                     presentation




                  testable
public function testShouldLoginWithARegisteredMsisdn()
{
    $self = $this;
    $msisdn = Baker::bake("Msisdn", "registered");
    $purchase = Baker::bake("Purchase", "from Country", $msisdn->country());

    $insertByUser = $msisdn->withoutNationalPrefixAsString();
    $this->request("POST", "/purchase/{$purchase->id()}/login")
        ->withBody(array("msisdn" => $insertByUser))
        ->run(function($response) use ($self) {
            $self->assertEquals(201, $response->status());
        });
}




                          testable
business
     logic

               http
                              presentation




    what
   about              presentation




old phones?
business




now
                  logic

                   http




                                     presentation


                                        http




  presentation
                      presentation
namespace HttpFeaturePhone
{
    class Client
    {
        public function next()
        {
            try {
                 $this->purchase();
                 $this->transferIn();
                 $this->optIn();
                 $this->waitForCompletion();
            } catch (ClientExit $exit) {
                 $exit->callHandler($this->callbacks);
            } catch (Exception $e) {
                 $exit = new ClientExit("error", $e->getMessage());
                 $exit->callHandler($this->callbacks);
            }
        }
        ...
    }
}                                   $client = new HttpFeaturePhoneClient($server, array(
                                       "onError" => function($error) use ($app) {
                                           $app->flash($error);
                                           $app->redirectTo($app->urlFor("error-ui"));
                                       },
                                       "onRoute" => function($route) use ($app) {
                                           $app->renderOrRedirectTo($route);
                                       },
                                       "onUrl" => function($url) use ($app) {
                                           $app->redirectTo($url);
                                       }
                                 ));
presentation


                                    http
   business
    logic

              http
                                                   presentation




                                           presentation




tomorrow...
questions?

Weitere ähnliche Inhalte

Andere mochten auch

[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMITí Bụng Bự
 
Minimum Viable Product
Minimum Viable ProductMinimum Viable Product
Minimum Viable ProductGabriele Lana
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented DesignGabriele Lana
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?Tushar Sharma
 
Professional Programmer
Professional ProgrammerProfessional Programmer
Professional ProgrammerGabriele Lana
 
Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Gabriele Lana
 
Agileday Coderetreat 2013
Agileday Coderetreat 2013Agileday Coderetreat 2013
Agileday Coderetreat 2013Gabriele Lana
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
It is not supposed to fly but it does
It is not supposed to fly but it doesIt is not supposed to fly but it does
It is not supposed to fly but it doesGabriele Lana
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 

Andere mochten auch (18)

[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
[Java] Khái niệm về RMI trong Java và cách sử dụng RMI
 
Minimum Viable Product
Minimum Viable ProductMinimum Viable Product
Minimum Viable Product
 
Magic of Ruby
Magic of RubyMagic of Ruby
Magic of Ruby
 
Why couchdb is cool
Why couchdb is coolWhy couchdb is cool
Why couchdb is cool
 
Nosql
NosqlNosql
Nosql
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented Design
 
MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?
 
Beyond Phoenix
Beyond PhoenixBeyond Phoenix
Beyond Phoenix
 
Professional Programmer
Professional ProgrammerProfessional Programmer
Professional Programmer
 
Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013
 
Agileday Coderetreat 2013
Agileday Coderetreat 2013Agileday Coderetreat 2013
Agileday Coderetreat 2013
 
coderetreat
coderetreatcoderetreat
coderetreat
 
CouchDB Vs MongoDB
CouchDB Vs MongoDBCouchDB Vs MongoDB
CouchDB Vs MongoDB
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
It is not supposed to fly but it does
It is not supposed to fly but it doesIt is not supposed to fly but it does
It is not supposed to fly but it does
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Denial Of Service Attack
Denial Of Service AttackDenial Of Service Attack
Denial Of Service Attack
 

Mehr von Gabriele Lana

Microservice Architectures
Microservice ArchitecturesMicroservice Architectures
Microservice ArchitecturesGabriele Lana
 
Professional Programmer 2018
Professional Programmer 2018Professional Programmer 2018
Professional Programmer 2018Gabriele Lana
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
Erlang: the language and the platform
Erlang: the language and the platformErlang: the language and the platform
Erlang: the language and the platformGabriele Lana
 
Resource Oriented Architectures
Resource Oriented ArchitecturesResource Oriented Architectures
Resource Oriented ArchitecturesGabriele Lana
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile DevelopmentGabriele Lana
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to ErlangGabriele Lana
 

Mehr von Gabriele Lana (8)

Microservice Architectures
Microservice ArchitecturesMicroservice Architectures
Microservice Architectures
 
Professional Programmer 2018
Professional Programmer 2018Professional Programmer 2018
Professional Programmer 2018
 
ProgrammingKatas
ProgrammingKatasProgrammingKatas
ProgrammingKatas
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Erlang: the language and the platform
Erlang: the language and the platformErlang: the language and the platform
Erlang: the language and the platform
 
Resource Oriented Architectures
Resource Oriented ArchitecturesResource Oriented Architectures
Resource Oriented Architectures
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile Development
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 

Kürzlich hochgeladen

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 

Kürzlich hochgeladen (20)

Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 

API Over HTTP

  • 2. presentation http business logic problem 1: presentation depends on the interaction flow, and mobile flows are really different
  • 3. presentation http business logic presentation http problem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  • 4. presentation http business logic presentation http problem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  • 5. presentation http business logic presentation http problem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  • 6. n io presentation t http a s e business logic r t e a v t presentation n s http c o problem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  • 7. n io presentation t http a ap s e pl business logic ic r t e a st at v t presentation at io n s http e n c o problem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  • 8. n io presentation t http a ap s e pl business r t presentation http business logic presentation http e a logic ic st at v t presentation at io n s http e n c o problem 2: (sessions) could make horizontal scalability harder than it should be
  • 9. n io presentation t http a ap s e pl business logic ic r t e a st at v t presentation at io n s http e n c o problem 2: (sessions) it’s very hard to migrate conversations from agents (mobile <-> desktop)
  • 10. logic business business business logic logic usage usage presentation presentation problem 3: http http business logic usage is duplicated
  • 11. business logic problem 3: business business logic logic (duplication) usage usage presentation presentation http http worst when there’s an anemic domain model
  • 12. presentation presentation http business logic presentation presentation http problem 4: rich client more duplication (different languages), more difficult to separate responsibilities (where is what?)
  • 13. presentation business http usage logic business logic presentation business http usage logic problem 5: (testability) difficult to reach a particular point in the conversation. presentation changes often (smell: divergent change)
  • 14. presentation business logic http presentation adopted solution
  • 15. SmartphoneClient.prototype.next = function() { var self = this this.seq( this.purchase, this.transferIn, this.optIn, this.waitForCompletion ).exit(function(exit) { exit.callHandler(self.callbacks) }) } var client = new SmartphoneClient(server, { onError: function(error) { app.pages.notify.error(error) }, onRoute: function(route) { app.goTo(route) }, onUrl: function(url) { location.href = url } })
  • 16. presentation business logic http presentation clear separation from application and conversation state
  • 17. presentation business logic http presentation stateless: easy to scale horizontally, conversations can be migrated/resumed
  • 18. $app->post("/purchase/:id/transfer-in/opt-in/pin", function($purchaseId) use($app) { ContentDelivery::on($app) ->process(function($request, $response) use($purchaseId, $app) { $purchase = Purchase::fromRequest($request, $purchaseId); $transferIn = $purchase->boundedTransferIn("pin-flow"); $transferIn->checkPin($request->params("pin")); $response->status(200); }) ->rescue('OnebipCoreNotSupportedActionInState', 409) ->rescue('OnebipPurchasePurchaseNotFound', 404) ->rescue('OnebipPurchaseTransferInNotFound', 404) ->rescue('OnebipPurchaseSpendingLimitReached', 403) ->rescue('OnebipPurchaseCheckPinFailed', 400) ->rescue('HttpUnauthenticatedRequest', 401) ->deliver(); } ); look, no session, and the controller code is really small
  • 19. presentation business logic http presentation clear application interface
  • 20. $app->map("/purchases", ... $app->get("/purchase/:id", ... $app->post("/purchase/:id/login", ... $app->get("/purchase/:id/buyer", ... $app->post("/purchase/:id/transfers-in", ... $app->get("/purchase/:id/transfer-in", ... $app->put("/purchase/:id/transfer-in", ... $app->post("/purchase/:id/transfer-in/opt-in/pin", ... $app->put("/purchase/:id/transfer-in/mo", ... clear application interface
  • 21. presentation business logic http presentation testable
  • 22. public function testShouldLoginWithARegisteredMsisdn() { $self = $this; $msisdn = Baker::bake("Msisdn", "registered"); $purchase = Baker::bake("Purchase", "from Country", $msisdn->country()); $insertByUser = $msisdn->withoutNationalPrefixAsString(); $this->request("POST", "/purchase/{$purchase->id()}/login") ->withBody(array("msisdn" => $insertByUser)) ->run(function($response) use ($self) { $self->assertEquals(201, $response->status()); }); } testable
  • 23. business logic http presentation what about presentation old phones?
  • 24. business now logic http presentation http presentation presentation
  • 25. namespace HttpFeaturePhone { class Client { public function next() { try { $this->purchase(); $this->transferIn(); $this->optIn(); $this->waitForCompletion(); } catch (ClientExit $exit) { $exit->callHandler($this->callbacks); } catch (Exception $e) { $exit = new ClientExit("error", $e->getMessage()); $exit->callHandler($this->callbacks); } } ... } } $client = new HttpFeaturePhoneClient($server, array( "onError" => function($error) use ($app) { $app->flash($error); $app->redirectTo($app->urlFor("error-ui")); }, "onRoute" => function($route) use ($app) { $app->renderOrRedirectTo($route); }, "onUrl" => function($url) use ($app) { $app->redirectTo($url); } ));
  • 26. presentation http business logic http presentation presentation tomorrow...