A few days ago John Horton Conway passed away, it inspired me to take a look at his Game of Life. I have it in my mind for years, since I heard about this cellular automaton on conferences. They were talking, it’s as a good challenge for Software Developers. Something like Kata to practice your skills using different approaches, libraries, toolsets.

I wanted to use it, to practice my UML skillset and the PlantUML tool. As an addition, I wrote PHP 7.3 code to demonstrate implantation. It’s far away from perfection. I didn’t use Composer, no Unit Tests, no framework, just vanilla PHP. Today, I wanted to make UML diagrams.

[toc]

UML – Unified Modeling Language – what is it?

UML Use Case Diagram

  1. Marcin starts game
  2. Marcin requests to evolve (build next stage)
  3. Marcin prints current stage
UML-Use-Case-GameOfLife

UML Class Diagram

Note 1. All rules related to decide is a Cell alive or dead should be always encapsulated in class Cell.

Note 2. It’s worth to create Interface behind BoardPrinter. We will be able to use a different format than HTML (ie. cli, gif).

Class 1: Board. It’s used to evolve all Cells at once and replace old ones by newborn.

Class 2: Cell. Cells are immutable. Since they were created, they can not change status or position. All rules to decide is a next Cell (replacer) will be alive or dead should be here.

Class 3: BoardPrinter. Printing or displaying should not be the responsibility of a Cell or a Board. We have to create a separate class for this aim. We will use simple HTML tag <table> to show results.

UML Sequence Diagram

  1. Marcin creates Cells (as many as needed)
  2. Returns Cells
  3. Creates Board with Cells
  4. Returns current Stage of Board
  5. Marcin asks to Print current Stage
  6. Asks for Cells from Board
  7. Returns Cells from Board
  8. Marcin requests Board to evolve (build next Stage)
  9. Requests Cells (by Board) to evolve (and pass neighbors Cells)
  10. Returns evolved Cell
  11. Replaces old Cell by evolved Cell
  12. Returns evolved Board (next Stage)
  13. Marcin asks to Print current Stage
  14. Asks for Cells from Board (and returns Cells from Board)
  15. Returns printed Stage of Board to Marcin

Note 3. Above and bellow, between 7. and 8. is missing one point: “Returns printed Stage of Board to Marcin”.

Extended UML Class Diagram with interfaces

Extra: Conway’s Law

I didn’t know till writing this post, and maybe you don’t know it as well. There are (at least) two Conways. First is known from The Game of Life. Second is known from Conway’s Law.

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization’s communication structure.

Melvin E. Conway