SlideShare a Scribd company logo
Use cases
            are
         important

Andrzej Krzywda
Use cases
in the code
     are
 even more
 important
class PlayTeamGameUseCase

  constructor: (@game, @player) ->
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)

  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()

    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)

  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()

    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->      Actors
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)

  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()

    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->      Actors
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)      Roles
  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()

    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->      Actors
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)      Roles
  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()          Algorithm
    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->      Actors
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)      Roles
  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()          Algorithm
    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()
                                                uses domain objects
    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
Name
class PlayTeamGameUseCase

  constructor: (@game, @player) ->      Actors
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)      Roles
  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

      @teachPlayerHowToPlay()          Algorithm
    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()
                                                uses domain objects
    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)       Nothing about GUI or persistence!
Where is?

• GUI
• Persistence
• API calls
• events
A clean use case code
   is the main goal
AOP + DCI
Aspect Oriented
 Programming
AOP gives us
method hooks
After, Before, Around
GUI & persistence
class GameUseCaseGlue
  constructor: (@gameUseCase, @game, @gui) ->

    execute: () =>
      Around(@gameUseCase,   'tryToEnterGameArea',                  @checkFbInvitation)
      After (@gameUseCase,   'tryToEnterGameArea',                  @showTeamArea)
      After (@gameUseCase,   'tryToEnterGameArea',                  @showButtonInviteOrPostPicture)
      Around(@gameUseCase,   'tellPlayerHeIsPartOfTeam',            @showTeamPopup)
      Around(@gameUseCase,   'askPlayerToLikeFanpage',              @showLikePopup)
      Around(@gameUseCase,   'teachPlayerHowToPlay',                @showTutorialPopup)
      Around(@gameUseCase,   'playerWantsToKnowWinnersWithPrize',   @showWinnersPopup)
      Around(@gameUseCase,   'playerWantsToKnowPrizes',             @showPrizesPopup)
      Around(@gameUseCase,   'askPlayerToDeclareHisFavCountry',     @showDeclareCountryPopup)
      Around(@gameUseCase,   'iAcceptMyFriendInvitationToATeam',    @onIAcceptMyFriendInvitationToATeam)

      Around(@gui, 'inviteClicked',    @inviteFriends)    # gameUseCase.inviteFriends
	
      Around(@gameUseCase, 'inviteFriends',    @storeInvitationInTheDB)     DB here

                                        Glue code
Around(@gameUseCase, 'tellPlayerHeIsPartOfTeam', @showTeamPopup)
(still glue code)

showTeamPopup: (proceed, friendsInviting) =>
  data = {inviting_friends: friendsInviting}
  popup = @popupsComponent.showPopup('team_popup', data)
  popup.onClose => proceed(friendsInviting))
DCI
class PlayTeamGameUseCase                 Use case == context
  constructor: (@game, @player) ->
    Role(@player, PlayerWithFriends)
    Role(@game,   TeamCompetition)         Roles injected runtime
  tryToEnterGameArea: () =>
    if @amIEnteringGameFirstTime()
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()
                                       data objects interact with
      @teachPlayerHowToPlay()
                                              each other
    else #n-th time...
      if @amICommingFromInvitation()
        @tellPlayerHeIsPartOfTeam()

    if @haveNotYetPickedFavPizzaCountry()
      @askPlayerToDeclareHisFavPizzaCountry()

  (more methods here)
class PlayerWithFriends
  setup: =>                                a role
    @friends = []
    @invitedFriends = []
    @acceptedFriends = []

  setInvitedFriends: (facebookUids) =>
    for facebookUid in facebookUids
      friend = new Friend({facebookUid: facebookUid})
      @invitedFriends.push(friend)

  setFriends: (friends) =>
    @friends = friends

  addFriend: (friend) =>
    existing = @getFriendByFacebookUid(friend?.facebookUid)
    if not existing?
      @friends.push(friend)
not only for
Single Page Applications
What use cases are in
   your project?
learn more about AOP and DCI and ...



   Enjoy writing
      elegant
     use cases!

More Related Content

PDF
Investigating Python Wats
PDF
Python for High School Programmers
PDF
pygame-enter-username-keep-top-ten-players
PDF
Palestra sobre Collections com Python
PDF
Introduction to Groovy
PDF
Python WATs: Uncovering Odd Behavior
PDF
Clustering com numpy e cython
PDF
ScotRuby - Dark side of ruby
Investigating Python Wats
Python for High School Programmers
pygame-enter-username-keep-top-ten-players
Palestra sobre Collections com Python
Introduction to Groovy
Python WATs: Uncovering Odd Behavior
Clustering com numpy e cython
ScotRuby - Dark side of ruby

What's hot (20)

PDF
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
PDF
穏やかにファイルを削除する
PDF
PDF
Slaying the Dragon: Implementing a Programming Language in Ruby
PDF
Elixir & Phoenix – fast, concurrent and explicit
PDF
Elixir & Phoenix – fast, concurrent and explicit
PDF
Ruby - Uma Introdução
PDF
An (Inaccurate) Introduction to Python
PDF
분데스리가====W­Е­4­9.сом====유료픽ポ프리메라리가ポ분데스리가일정
PDF
Get Kata
PDF
Functional Programming & Event Sourcing - a pair made in heaven
PDF
CoffeeScript
PDF
Real world gobbledygook
ODP
Test du futur avec Spock
PDF
Bringing Characters to Life for Immersive Storytelling - Dioselin Gonzalez
ODP
The bones of a nice Python script
PPTX
Bringing characters to life for immersive storytelling
PDF
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
PDF
Programação Funcional
PDF
SecureSocial - Authentication for Play Framework
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
穏やかにファイルを削除する
Slaying the Dragon: Implementing a Programming Language in Ruby
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
Ruby - Uma Introdução
An (Inaccurate) Introduction to Python
분데스리가====W­Е­4­9.сом====유료픽ポ프리메라리가ポ분데스리가일정
Get Kata
Functional Programming & Event Sourcing - a pair made in heaven
CoffeeScript
Real world gobbledygook
Test du futur avec Spock
Bringing Characters to Life for Immersive Storytelling - Dioselin Gonzalez
The bones of a nice Python script
Bringing characters to life for immersive storytelling
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Programação Funcional
SecureSocial - Authentication for Play Framework
Ad

Similar to Use cases in the code with AOP (20)

PDF
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
PDF
The main class of the tictoe game looks like.public class Main {.pdf
PDF
Team public class Team {    private String teamId;    priva.pdf
PDF
Here are the instructions and then the code in a sec. Please R.pdf
PDF
Thanks so much for your help. Review the GameService class. Noti.pdf
PDF
SCBCN17 - El camino hacia la programación declarativa
PDF
Sharable_Java_Python.pdf
PDF
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
PDF
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
PDF
Symfony2 - extending the console component
PDF
public interface Game Note interface in place of class { .pdf
PDF
[EN] Ada Lovelace Day 2014 - Tampon run
PDF
I really need some help if I have this right so far. PLEASE CHANG.pdf
PDF
package com.test;public class Team {    private String teamId;.pdf
PDF
I really need some help if I have this right so far. Please Resub.pdf
PDF
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
PDF
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
PDF
The Ring programming language version 1.6 book - Part 51 of 189
PDF
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
PDF
package com.tictactoe; public class Main {public void play() {.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
The main class of the tictoe game looks like.public class Main {.pdf
Team public class Team {    private String teamId;    priva.pdf
Here are the instructions and then the code in a sec. Please R.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
SCBCN17 - El camino hacia la programación declarativa
Sharable_Java_Python.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Symfony2 - extending the console component
public interface Game Note interface in place of class { .pdf
[EN] Ada Lovelace Day 2014 - Tampon run
I really need some help if I have this right so far. PLEASE CHANG.pdf
package com.test;public class Team {    private String teamId;.pdf
I really need some help if I have this right so far. Please Resub.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
The Ring programming language version 1.6 book - Part 51 of 189
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
package com.tictactoe; public class Main {public void play() {.pdf
Ad

More from Andrzej Krzywda (20)

PDF
[PL] PRUG Luty 2022 - Service objecty to za mało - jak żyć z Railsami?
PDF
[PL] Service objecty to za mało - jak żyć z Railsami?
PDF
Audit log with event sourcing
PDF
Event driven without microservices
PDF
From legacy to DDD - 5 starting steps
PDF
Slack protips from Arkency
PDF
From Rails legacy to DDD - Pivorak, Lviv
PDF
From legacy to DDD (slides for the screencast)
PDF
From legacy to DDD
PDF
DCI - the architecture from the future
PDF
Refactoring Rails applications with RubyMine
PDF
Beyond The Rails Way
PDF
Service objects in Rails tests - factory_girl replacement
PDF
Developer oriented
PDF
Can you TDD Rails?
PDF
A programmer or a business consultant?
PDF
Rails refactoring call for help
PDF
[Polish] Praca zdalna, praca asynchroniczna
KEY
Single Page Applications with CoffeeScript [Polish]
PDF
Madeleine on Rails
[PL] PRUG Luty 2022 - Service objecty to za mało - jak żyć z Railsami?
[PL] Service objecty to za mało - jak żyć z Railsami?
Audit log with event sourcing
Event driven without microservices
From legacy to DDD - 5 starting steps
Slack protips from Arkency
From Rails legacy to DDD - Pivorak, Lviv
From legacy to DDD (slides for the screencast)
From legacy to DDD
DCI - the architecture from the future
Refactoring Rails applications with RubyMine
Beyond The Rails Way
Service objects in Rails tests - factory_girl replacement
Developer oriented
Can you TDD Rails?
A programmer or a business consultant?
Rails refactoring call for help
[Polish] Praca zdalna, praca asynchroniczna
Single Page Applications with CoffeeScript [Polish]
Madeleine on Rails

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm

Use cases in the code with AOP

  • 1. Use cases are important Andrzej Krzywda
  • 2. Use cases in the code are even more important
  • 3. class PlayTeamGameUseCase constructor: (@game, @player) -> Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 4. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 5. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Actors Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 6. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Actors Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) Roles tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 7. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Actors Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) Roles tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() Algorithm else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 8. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Actors Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) Roles tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() Algorithm else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() uses domain objects if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 9. Name class PlayTeamGameUseCase constructor: (@game, @player) -> Actors Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) Roles tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() @teachPlayerHowToPlay() Algorithm else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() uses domain objects if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here) Nothing about GUI or persistence!
  • 10. Where is? • GUI • Persistence • API calls • events
  • 11. A clean use case code is the main goal
  • 17. class GameUseCaseGlue constructor: (@gameUseCase, @game, @gui) -> execute: () => Around(@gameUseCase, 'tryToEnterGameArea', @checkFbInvitation) After (@gameUseCase, 'tryToEnterGameArea', @showTeamArea) After (@gameUseCase, 'tryToEnterGameArea', @showButtonInviteOrPostPicture) Around(@gameUseCase, 'tellPlayerHeIsPartOfTeam', @showTeamPopup) Around(@gameUseCase, 'askPlayerToLikeFanpage', @showLikePopup) Around(@gameUseCase, 'teachPlayerHowToPlay', @showTutorialPopup) Around(@gameUseCase, 'playerWantsToKnowWinnersWithPrize', @showWinnersPopup) Around(@gameUseCase, 'playerWantsToKnowPrizes', @showPrizesPopup) Around(@gameUseCase, 'askPlayerToDeclareHisFavCountry', @showDeclareCountryPopup) Around(@gameUseCase, 'iAcceptMyFriendInvitationToATeam', @onIAcceptMyFriendInvitationToATeam) Around(@gui, 'inviteClicked', @inviteFriends) # gameUseCase.inviteFriends Around(@gameUseCase, 'inviteFriends', @storeInvitationInTheDB) DB here Glue code
  • 19. (still glue code) showTeamPopup: (proceed, friendsInviting) => data = {inviting_friends: friendsInviting} popup = @popupsComponent.showPopup('team_popup', data) popup.onClose => proceed(friendsInviting))
  • 20. DCI
  • 21. class PlayTeamGameUseCase Use case == context constructor: (@game, @player) -> Role(@player, PlayerWithFriends) Role(@game, TeamCompetition) Roles injected runtime tryToEnterGameArea: () => if @amIEnteringGameFirstTime() if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() data objects interact with @teachPlayerHowToPlay() each other else #n-th time... if @amICommingFromInvitation() @tellPlayerHeIsPartOfTeam() if @haveNotYetPickedFavPizzaCountry() @askPlayerToDeclareHisFavPizzaCountry() (more methods here)
  • 22. class PlayerWithFriends setup: => a role @friends = [] @invitedFriends = [] @acceptedFriends = [] setInvitedFriends: (facebookUids) => for facebookUid in facebookUids friend = new Friend({facebookUid: facebookUid}) @invitedFriends.push(friend) setFriends: (friends) => @friends = friends addFriend: (friend) => existing = @getFriendByFacebookUid(friend?.facebookUid) if not existing? @friends.push(friend)
  • 23. not only for Single Page Applications
  • 24. What use cases are in your project?
  • 25. learn more about AOP and DCI and ... Enjoy writing elegant use cases!

Editor's Notes