SlideShare a Scribd company logo
1 of 27
Download to read offline
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?

More Related Content

Viewers also liked

[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
 

Viewers also liked (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
 

More from 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
 

More from 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
 

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Stateless conversation architecture for mobile applications

  • 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...