SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
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?

Más contenido relacionado

Destacado

[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
 

Destacado (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
 

Más de 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
 

Más de 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
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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.pdfsudhanshuwaghmare1
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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 MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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.pptxEarley Information Science
 
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...Enterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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 Servicegiselly40
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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