Software Architecture: Conway's Game of Life: Clean Architecture, Design Patterns, Signal R, Hosted Services, .Net Core 3.1 and Angular 8
Conway's Game of Life is a zero player board game with no winning or losing. This means there is no input and it uses a set of rules to evolve from its initial state. The board's cells can either have a dead or live state.
Explaining Conway's' Game of Life is not the purpose of this article for more details please see [1] or other sources. The purpose of the article is to teach architectural principles and how to apply these principles when solving problems.
The the final demo is shown in the following video:
Entities
The board is made up of cells and the cell is the only entity that can be saved in the database. The cell has three properties that is: Column, Row and CellState.
Clean Architecture
Core
Design Patterns
The Observer Design Pattern and Singleton Design Pattern were used to implement Conway's Game of Life.
Observer Design Pattern
The game is the concrete subject and the zero player is the concrete observer.
Observer:
Concrete Observer:
The concrete observer implements the observer which happens to be an interface and therefore it must implement the Update method as shown in the image below:
The RuleCheck method is responsible for updating each cell's state on the board.
Subject:
Concrete Subject and Singleton:
The concrete observer is also a singleton since there is only one board in this game. The constructor also sets the initial state of the game by calling a method called Initialize as shown in the diagram below.
The concrete subject inherits from the subject which happens to be an interface therefore the Start, Stop and Notify methods must be implemented as shown below:
UI/Web
Conclusion
This article serves as a guideline on how to apply programming principles when solving problems using the latest technology. In this case the problem to be solved is Conway's Game of Life.
The source code can be found on the following source control: https://github.com/mandavamunya/GameOfLife
Reference
- https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life