Skip to content

Instantly share code, notes, and snippets.

@ericnormand
Last active November 18, 2025 13:35
Show Gist options
  • Select an option

  • Save ericnormand/b25712186bb210ab1c52f06655e7dfbd to your computer and use it in GitHub Desktop.

Select an option

Save ericnormand/b25712186bb210ab1c52f06655e7dfbd to your computer and use it in GitHub Desktop.
# Coffee shop scenario
Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.*
Jill starts to order some coffee at the touchscreen. She adds a small, dark roast. Then
she adds a large medium roast with double almond syrup. She adds a
medium medium roast with two soy milk shots (the second one by
accident). She reads the price and it's too expensive. So she removes
the second coffee (the one with the almond syrup). Then she realizes
the third coffee has two soy milk shots and she removes one. The price
looks good, so she submits the order.
@austin-meier
Copy link

austin-meier commented Nov 12, 2025

  • Jill starts to order some coffee at the touchscreen

    • (defn new-order []) ;; => Order
  • She adds a small dark roast

    • (defn new-coffee) ;;=> Coffee
    • (defn set-size [coffee size]) ;; => Coffee
    • (defn set-roast [coffee roast]) ;; => Coffee
    • (defn add-to-order [order item]) ;; => Order
  • Then she adds a large medium roast with double almond syrup

    • (defn add-ingredient [coffee ingredient]) ;; => Coffee
    • (defn remove-ingredient [coffee ingredient]) ;; => Coffee
    • (defn update-coffee [order uuid coffee-fn]) ;; => Coffee
  • She adds a medium roast with two soy milk shots (the second by by accident)

  • She reads the price and it's too expensive so she removes the second coffee (the one with almond syrup)

    • (defn order-price [order]) ;; => Double
    • (defn remove-from-order [order item-id]) ;; => Order
  • Then she realizes the third coffee has two soy milk shots and she removes one.

    • (defn coffee-by-uuid [order uuid]) ;; => Coffee
    • (defn update-coffee [order uuid coffee-fn]) ;; => Coffee
  • The price looks good, so she submits the order

    • (defn submit-order! [order] ;; throwable)
  • Jill starts to order some coffee at the touchscreen

(def jill (new-order))
  • She adds a small dark roast
(-> jill
  (add-to-order (-> new-coffee (set-size :medium) (set-roast :dark)))
  • Then she adds a large medium roast with double almond syrup
(-> jill
  (add-to-order 
	(-> new-coffee
	  (add-ingredient :almond-syrup)
	  (add-ingredient :almond-syrup))))
  • She adds a medium roast with two soy milk shots (the second by by accident)
(-> jill
  (add-to-order 
	(-> new-coffee
	  (add-ingredient :soy-milk-shot)
	  (add-ingredient :soy-milk-shot))))
  • She reads the price
(order-price jill)
  • and it's too expensive so she removes the second coffee (the one with almond syrup)
;; assuming the UI carries the item ID in the list and passes it
(-> jill
	(remove-from-order second-coffee-id))
  • Then she realizes the third coffee has two soy milk shots and she removes one.
    ;; assuming the UI carries the item ID in the list and passes it
;; assuming the UI carries the item ID in the list and passes it
(-> jill
	(update-coffee second-coffee-id #(remove-ingredient % :soy-milk-shot))))
  • The price looks good, so she submits the order
(-> jill
	(submit-order!))

@gleenn
Copy link

gleenn commented Nov 12, 2025

My domain model of the problem using Clojure

Jill starts to order some coffee at the touchscreen.
;; Order
(defn start-order []) ;; => Order

She adds a small, dark roast.
;; Coffee
(defn create-coffee ^Coffee [])
(defn set-size ^Coffee [coffee size])
(defn set-roast ^Coffee [coffee roast])
(defn add-coffee-to-order ^Coffee [order coffee])

Then she adds a large medium roast with double almond syrup.
;; Syrup
(defn set-syrup ^Coffee [coffee syrup])

;; Milk
She adds a medium medium roast with two soy milk shots (the second one by accident).
(defn set-milk ^Coffee [coffee milk])
(defn set-milk-quantity ^Coffee [coffee milk quantity])

She reads the price and it's too expensive.
(defn get-price ^float [coffee])

So she removes the second coffee (the one with the almond syrup).
(defn remove-coffee-from-order ^Order [order coffee])

Then she realizes the third coffee has two soy milk shots and she removes one.
;; repeat of (defn set-milk-quantity ^Coffee [coffee milk quantity])

The price looks good, so she submits the order.
(defn complete-order [order])

@JohanCodinha
Copy link

JohanCodinha commented Nov 12, 2025

Coffee shop scenario

Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.

Jill starts to order some coffee at the touchscreen.
;; Order
(defn start-order []) ;;=> Order

(def order0 (start-order))

She adds a small, dark roast.

;; Item
(defn ->Item [options]) ;;=> Item
(defn change-order [order operation item]) ;;=> Order

(def order1 (change-order order0 :add (->Item ...))

Then she adds a large medium roast with double almond syrup.

(def order2 (change-order order1 :add (->Item ...))

She adds a medium medium roast with two soy milk shots (the second one by
accident).

(def order3 (change-order order0 :add (->Item ...))

She reads the price and it's too expensive.

So she removes the second coffee (the one with the almond syrup).
(def order4 (change-order order3 :remove ...)

Then she realizes the third coffee has two soy milk shots and she removes one.
(def order5 (change-order order4 :remove ...)
(def order6 (change-order order5 :add (->Item ...))

The price looks good, so she submits the order.
(defn submit-order [order]) ;; => Order-submission

(submit-order order6)

@KJBrock
Copy link

KJBrock commented Nov 12, 2025

Coffee shop scenario

Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.

Jill starts to order some coffee at the touchscreen.

(defn create-order []);; => Order

;; Order

She adds a small, dark roast. Then

(defn create-coffee []) ;; => Coffee
(defn add-coffee [order, coffee];; => Order

;; Coffee

(defn set-roast [coffee, roast]) ;; => Coffee
(defn set-size [coffee size]) ;; => Coffee

;; Roast
;; Size

she adds a large medium roast with double almond syrup.

(defn set-syrup [coffee, syrup, count]) ;; = Coffee

;; Syrup - type of syrup

She adds a medium medium roast with two soy milk shots

(defn add-milk [coffee, milk]);; => Coffee

;; Milk -- type of milk

(the second one by accident). She reads the price and it's too expensive.

So she removes
the second coffee (the one with the almond syrup).

(defn remove-coffee [order, coffee]) ;; => Order

Then she realizes the third coffee has two soy milk shots and she removes one.

(defn remove-milk [coffee, milk]);; => Coffee

The price looks good, so she submits the order.

(defn submit-order [order]) ;; => True/False

@soyPabloG
Copy link

soyPabloG commented Nov 12, 2025

Coffee shop scenario Background:

This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop.

Jill is a customer who wants some coffee.
(Defn create-order []) ;; => Order

Jill starts to order some coffee at the touchscreen.
(Defn add-item [Order Item]) ;; => Order

She adds a small, dark roast.
(Defn create-coffee []) ;; => Coffee
(Defn set-size [coffee size]) ;; => Coffee
(Defn set-roast [coffee roast]) ;; => Coffee

Then she adds a large medium roast with double almond syrup.
(Defn set-flavor [coffee flavor]) ;; => Coffee
(Defn set-flavor [coffee flavor shots]) ;; => Coffee

She adds a medium medium roast with two soy milk shots (the second one by accident).
She reads the price and it's too expensive.

(Defn get-price [order]) ;; => price

So she removes the second coffee (the one with the almond syrup).

(Defn remove-item [Order item-id]) ;; Order

Then she realizes the third coffee has two soy milk shots and she removes one.
(Defn set-milk-type [coffee milk-type]) ;; Coffee
(Defn set-milk-type [coffee milk-type shots]) ;; Coffee

The price looks good, so she submits the order.
(Defn submit [Order]) ;; => Order

@slipset
Copy link

slipset commented Nov 12, 2025

Coffee shop scenario

Background: This scenario is from a self-service ordering touchscreen
at a coffee shop that you are assigned to develop. Jill is a customer
who wants some coffee.

Jill starts to order some coffee at the touchscreen. (defn order [])
;;=> order

;; Order

She adds a small, dark roast. Then (defn coffee []) ;; coffee (defn
set-size [coffee size]) ;; coffee (defn set-roast [coffe roast]) ;;
coffee

;; Coffee Size small, large, medium Roast dark, medium

(defn add [order coffee] ;; Order she adds a large medium roast with
double almond syrup.

(defn add-syrup [coffee syrup]) ;; coffee

;; Syrup

(defn add-milk [coffee type]) ;; coffe

;; Milk soy

She adds a medium medium roast with two soy milk shots (the second one
by accident).

She reads the price and it's too expensive.

(defn get-price [order]) ;; price

So she removes the second coffee (the one with the almond syrup).
(defn remove [order item]) ;; order

Then she realizes the third coffee has two soy milk shots and she
removes one.

;; implement by remove and add new

The price looks good, so she submits the order.

(defn submit! [order]) ;; => void

@emil0r
Copy link

emil0r commented Nov 12, 2025

Coffee shop scenario

;; Background: This scenario is from a self-service ordering touchscreen at a
;; coffee shop that you are assigned to develop. Jill is a customer who wants
;; some coffee.

;; order: Jill starts to order
;; coffee: some coffee at the touchscreen.
;; roast: She adds a small, dark roast.
;; amend-order: Then she adds a
;; coffee: large medium roast
;; complement syrup: with double almond syrup.
;; amend-order: She adds a medium
;; roast: medium roast
;; complement soy milk: with two soy milk shots
;; complement soy milk - second time: (the second one by accident).
;; She reads the price and it's too expensive.
;; amend-order (by index): So she removes the second coffee (the one with the almond syrup).
;; amend-order (remove complement by index to a coffee): Then she realizes the third coffee has two soy milk shots and she removes one.
;; execute-order: The price looks good, so she submits the order.

;; parts
;; - order - [index of coffees]
;; - coffee - [type, complements]
;; - complement - [type]

@wproffitt-elder
Copy link

wproffitt-elder commented Nov 12, 2025

;::  # Coffee shop scenario

;:: Background: *This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.*

;:: Jill starts to order 

(defn start-order []) ; => Order

;:: some coffee at the touchscreen. 

(defn add-item [order]) ; => Order with a Coffee Item

;:: She adds a small, dark roast. 

(defn add-item [order]) ; => Order with a Coffee Item with two Details

;:: Then she adds a large medium roast with double almond syrup.

(defn add-item [order]) ; => Order with two specific Coffees,
; the latter of which has three Details, one of which has a quantity of 2

;:: She adds a medium medium roast with two soy milk shots (the second one by accident). 

(defn add-item [order]) ; => Order with three specific Coffees,
; the latter of which again has three Details, one with a quantity of 2

;:: She reads the price and it's too expensive. 

(defn calculate-price [order]) ; => BigDecimal

;:: So she removes the second coffee (the one with the almond syrup). 

(defn remove-item [order item]) ; => nil, and how to identify the item is a consideration

;:: Then she realizes the third coffee has two soy milk shots and she removes one. 

(defn display-order [order]) ; => visual; depending on UI, might be how she notices
; Similar use of remove-item as above


;:: The price looks good, so she submits the order.

(defn submit-order [order]) ; => nil

@joshuamzm
Copy link

Coffee shop scenario

Background: This scenario is from a self-service ordering touchscreen at a coffee shop that you are assigned to develop. Jill is a customer who wants some coffee.

(ns domain-exercise)

(defn create-order [])                                      ;;=> order
;; Jill starts to order some coffee at the touchscreen.

(defn add-coffee [order & {:keys [size]}])                  ;;=> order
;; She adds a small, dark roast.

(defn change-coffee [order coffee-id & {:keys [size addons]}]) ;;=> order
;; Then she adds a large medium roast with double almond syrup.

(defn add-coffee [order & {:keys [size addons]}])           ;;=> order
;; She adds a medium medium roast with two soy milk shots (the second one by accident).

(defn remove-coffee [order coffee-id])                      ;;=> order
;; She reads the price and it's too expensive. So she removes the second coffee (the one with the almond syrup).

(defn change-coffee [order coffee-id & {:keys [addons]}])   ;;=> order
;; Then she realizes the third coffee has two soy milk shots and she removes one.

(defn submit-order [order-id])                              ;;=> order
;; The price looks good, so she submits the order.

@jvargas
Copy link

jvargas commented Nov 12, 2025

Jill starts to order some coffee at the touchscreen.

;; Order
(defn create-order []) ;;=> Order
;; Coffee
(defn create-coffee []) ;;=> Coffee

She adds a small, dark roast.

(defn coffee-size [coffee size])    ;;=> Coffee
(defn coffee-roast [coffee roast])  ;;=> Coffee
(defn add-to-order [coffee] ;=> Order

Then she adds a large medium roast with double almond syrup.

(defn coffee-syrup [coffee syrup]   ;=> Coffee

She adds a medium medium roast with two soy milk shots (the second one by accident).

(defn coffee-mix-in [coffee mix])   ;;=> Coffee

She reads the price and it's too expensive.

So she removes the second coffee (the one with the almond syrup).

Then she realizes the third coffee has two soy milk shots and she removes one.

The price looks good, so she submits the order.

@emil0r
Copy link

emil0r commented Nov 18, 2025

Coffee shop scenario

;; Background: This scenario is from a self-service ordering touchscreen at a
;; coffee shop that you are assigned to develop. Jill is a customer who wants
;; some coffee.

;; order: Jill starts to order
;; coffee: some coffee at the touchscreen.
;; roast: She adds a small, dark roast.
;; amend-order: Then she adds a
;; coffee: large medium roast
;; complement syrup: with double almond syrup.
;; amend-order: She adds a medium
;; roast: medium roast
;; complement soy milk: with two soy milk shots
;; complement soy milk - second time: (the second one by accident).
;; She reads the price and it's too expensive.
;; amend-order (by index): So she removes the second coffee (the one with the almond syrup).
;; amend-order (remove complement by index to a coffee): Then she realizes the third coffee has two soy milk shots and she removes one.
;; execute-order: The price looks good, so she submits the order.

;; parts
;; - order - [index of coffees]
;; - coffee - [type, complements]
;; - complement - [type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment