How we Made a Trading Application using Clean Architecture
In the summer of 2020, I had the pleasure of taking CSC207 and working on a trading system in Java. To learn about how the project works, you can watch this video made by Ethan Lam, one of the group members. In this blog post, I will explain the code structure and some of the tools that were required to complete the project.
Code Structure
The project was made in Java based on the Clean Architecture guidelines by Robert C. Martin. The book suggests separating the project into layers, as shown in Figure 1. The main rule of Clean Architecture is that dependencies point inwards. Details depend on abstractions.
Here is some useful terminology that I will be referencing:
- Entities: Classes that store information about themselves.
- Use Cases: Classes that modify values inside Entities and control what is allowed to happen to an entity.
- Controllers: Determine which actions the user is allowed to do and direct user input into use cases.
- Presenters: Gather and format information so that it can be sent to the view.
We used packages to separate each layer. Each package reresents a layer of Clean Architecture. Here is how the file structure looks like:
Graphical User Interface
The Graphical User Interface (GUI) files are stored in the view package. This package is separated from the main layers. The presenters are responsible for formatting data into the GUI. The views call the controllers to determine which actions are allowed.
We used the JavaFx library. One of the core advantages of JavaFx is the integration with the FX Markup Language (FXML). FXML files allow designers to create views through a drag-and-drop interface known as the Scene Builder (see Figure 3). These files are stored separately and are loaded by the view layer.
Multi-Language Support
The project supports the ability to switch the current language. We implemented this feature using property changes at the presenters layer. Java’s ResourceBundle library loads the resources of the corresponding language. The resources themselves are stored in a separate package. These files map property values to the corresponding language as shown in Figure 4. The presenters are responsible for accessing the ResourceBundle and presenting the right language to the user.