Skip to content

Latest commit

 

History

History
48 lines (26 loc) · 1.5 KB

File metadata and controls

48 lines (26 loc) · 1.5 KB

Refactoring Practice

Copy this template repository to your own Github account. Then clone it to your computer and do the refactorings. Push your work to Github.

Each subdirectory contains some code that needs refactoring.

  1. In this README, write one line describing each refactoring you apply and why.
  2. Perform the refactoring in the subdirectory code.

time/timestamp.py

Refactor timestamp.py. 2 or 3 refactorings are possible.

game_framework/gamelib.py

Look for refactorings in the class GameApp.

  • Avoid side-effects: replace side effect with return value (the caller must use the return value)

  • Encapsulate a collection - provide behavior that subclasses of GameApp need instead of requiring them to manipulate a collection that belongs to the GameApp class.

    • Hint: elements

recipe/recipe.py and recipe/main.py

This uses a dataclass, which requires Python 3.7.

The Recipe class defines a recipe for a hot beverage with attributes:

  • name - name of the recipe
  • coffee - units of coffee
  • chocolate - units of chocolate
  • milk - units of milk
  • sugar - units of sugar
  • price - (float) price in Baht

Refactor main.py. What can you do to eliminate the long, boring code?

Resources