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:
- Why sometimes the code is hard to maintain?
- Why is it so hard to implement tests?
- 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."
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.
- Episode I: Decoupling the Problem Aiming Testability - (WE ARE HERE!)
- Episode II: Increasing Decoupling (Event Queue)
- Episode III: Increasing Decoupling, Testability and Scalability (SpringBoot and Docker)
- Episode IV: High Scalability (Spring Cloud MicroServices)
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.
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".
In this episode, It was implemented only the unit tests.
- GIT
- JDK 8+
- Clone the repository: git clone -b master-sync https://github.com/wmaduro/clean-architecture-study.git
- Jump into the project folder: cd clean-architecture-study
- Change permission: chmod +x mvnw
- Compile using built-in maven (notice that all unit tests will be triggered): ./mvnw clean package
- 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.
- Implement the integrated test.