Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Theatrical players - refactoring Kata

Yoan
October 16, 2019

Theatrical players - refactoring Kata

A refactoring kata done in several teams to understand Approval tests and how to refactor legacy code with :
- OOP paradigms
- FP paradigms

Yoan

October 16, 2019
Tweet

More Decks by Yoan

Other Decks in Programming

Transcript

  1. @algrison @yot88 Objective • Learn how to refactor “legacy” code

    • Practice FP concepts Theatrical players refactoring Kata Exercise • Add an HTML output with the same information
  2. Will it be easy to do the exercise ? Why

    ? What do you think about this code ? https://github.com/emilybache/Theatrical-Players-Refactoring-Kata
  3. @algrison @yot88 Which kind of tests ? The code already

    exists and works : • Easiest way to add a regression test is to find some test data, exercise the code, and approve the result • Add approval tests / snapshot tests / Golden master
  4. @algrison @yot88 Approval tests : Generate output Statement for BigCo

    Hamlet: $650.00 (55 seats) As You Like It: $580.00 (35 seats) Othello: $500.00 (40 seats) Amount owed is $1,730.00 You earned 47 credits
  5. @algrison @yot88 Approval tests : Create a test https://approvaltests.com/ Statement

    for BigCo Hamlet: $650.00 (55 seats) As You Like It: $580.00 (35 seats) Othello: $500.00 (40 seats) Amount owed is $1,730.00 You earned 47 credits StatementPrinterTests.exampleStatem ent.approved.txt
  6. @algrison @yot88 Step by step (OO style) 1) Extract the

    amount calculation • For example you can use the Strategy pattern o Tragedy & Comedy • You can also use some kind of factory to retrieve the correct impl. 2) Extract the credits calculation 3) Create a specific Printer implementation • print(Line) • print(Statement)
  7. @algrison @yot88 Step by step (FP style) 1) Extract the

    amount calculation • Create dedicated functions for both types • Tragedy & Comedy • Build a map of these implementations 2) Build a statement 3) Run the pipeline • Iterate • Reduce • Format