Giter Club home page Giter Club logo

clean-architecture-study's Introduction

Clean Architecture Study Series

This series intends to be a hands-on discussion about ways to get a better code-design. It will mainly cover the following perspectives:

  • Decoupling
  • Testability
  • Scalability

The initial questions that motivated this series were:

  1. Why sometimes the code is hard to maintain?
  2. Why is it so hard to implement tests?
  3. Why implementing tests seems to be too expensive?

Now, after some progress working on those dilemmas, I would guess that: "It is hard to implement tests in code that was not built meant to be tested! The way we think and implement our solutions impacts directly on its testability and maintainability."

The Problem

As a target problem, It was chosen something relatively simple: Read lines from a file, process them and show the result.

The problem itself is just a poker hands evaluation and show basic statistics.

Episodes

Episode I: Decoupling the Problem Aiming Testability

The main idea of this episode is to breakdown the problem in small services. Each service produces its output object (DTO) that can be shared with other services as input parameters. It is important to mention that "the service" must enclose all resources and logic needed to process its data and generate its outcome.

Decoupling

alt text

File Parser Service

  • Responsibility: Process the file content and parse the lines to a list of hand's objects.
  • Consume: Hand's file.
  • Produce: List of hand's objects.

Hand Mapper Service

  • Responsibility: Organize the hand's objects in blocks per hand code.

  • Consume: Outcome of "File Parser Service".

  • Produce: Map of hand's grouped by hand code.

Hand Evaluator Service

  • Responsibility:

    • Identify the best cards in the hand.
    • Evaluate if the best card had won the hand.
    • Filter the content by player name and/or aggressivity behaviour (optional).
  • Consume: Outcome of "Hand Mapper Service".

  • Produce: List of the winner's hands and its evaluation.

Hand Type Service

  • Responsibility: Organize the data in groups of hand types ("Best Hand Win", "Worst Hand Win" and "Tied").

  • Consume: Outcome of "Hand Evaluator Service".

  • Produce: Hand Types Mapped.

Hand Type Viewer Service

  • Responsibility: Show the evaluation statistic.

  • Consume: Outcome of "Hand Type Service".

Project Overview

alt text

Tests

In this episode, It was implemented only the unit tests.

How to run

Requirement(s)

  • GIT
  • JDK 8+

Step by Step (LINUX)

  1. Clone the repository: git clone -b master-sync https://github.com/wmaduro/clean-architecture-study.git
  2. Jump into the project folder: cd clean-architecture-study
  3. Change permission: chmod +x mvnw
  4. Compile using built-in maven (notice that all unit tests will be triggered): ./mvnw clean package
  5. Run: java -cp 'target/lib/*:target/clean-architecture-study-0.0.1-SNAPSHOT-jar-with-dependencies.jar' com.maduro.poker.ClenArchitectureStudyApplication

Optionally, you can import the project in Eclipse 4+ with maven plugins installed.

Backlog

  1. Implement the integrated test.

clean-architecture-study's People

Contributors

wmaduro avatar

Watchers

 avatar

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.