Software Architecture: Conway's Game of Life: Clean Architecture, Design Patterns, Signal R, Hosted Services, .Net Core 3.1 and Angular 8
Image by Munyaradzi Mandava

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.

No alt text provided for this image

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.

No alt text provided for this image

Clean Architecture

Core

No alt text provided for this image

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:

No alt text provided for this image

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:

No alt text provided for this image

The RuleCheck method is responsible for updating each cell's state on the board.

Subject:

No alt text provided for this image

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.

No alt text provided for this image

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:

No alt text provided for this image

UI/Web

No alt text provided for this image

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

  1. https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

To view or add a comment, sign in

More articles by Munyaradzi Mandava

Explore content categories