Giter VIP home page Giter VIP logo

rental-refactored's Introduction

「リファクタリング」本、「最初の例」のリファクタリング

概要

マーチンファウラー「リファクタリング」の最初の例をリファクタリング。

書籍のオリジナルに若干手を入れた、リファクタリング前のコード

リファクタリング前

リファクタリングの方針

関心事の分離を徹底する。 具体的には、以下を実施。

ビューとモデルの分離

  • レンタル内容を表示する Statement クラスを導入し、persentationパッケージに配置
  • レンタルの料金計算・ポイント計算を modelパッケージに配置

料金とポイントの分離

以下の二つをパッケージ単位に分割

  • 料金計算の区分と計算ロジック -> charge パッケージ
  • ポイント計算の区分と計算ロジック -> point パッケージ

タイプ判定とタイプごとの料金計算/ポイント計算の分離

  • 料金計算のタイプ判定はRental クラスが行う

  • 料金タイプごとの料金計算は、ChargeType クラス(振る舞いを持った列挙型)

  • ポイント計算のタイプ判定もRentalクラスが行う

  • ポイントタイプごとのポイント計算は、PointTypeクラス(振る舞いを持った列挙型)

合計計算

レンタルのリストからの料金合計、同じくレンタルのリストからのポイント合計の計算処理を、Tatal クラスに分離して共通化。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.