Skip to content
sultanofendymion edited this page Jan 9, 2020 · 2 revisions

Introduction

As described in README.MD before, we decide to remove api link when we deploy to Github. Therefore, there is no need to input username.

UML Diagram

connect4 Chip

  • Consists of 2 Chips which are red and yellow. If there is no chip in any grids, it will store NullChip instead.

ChipFactory

  • Provides a way to create an object without exposing the creation logic to the client. It will check whether corresponding object is created. If it is, then returns that object but if it is not created, creates it and stores in HashMap first then return that object.

Board

  • A board that is used to play. First, it will start with filling all array with NullChip. Board can add chip, clean and can tell if it is full.

CheckStrategy

  • A class that is used to check the winner in the board. It will check each time the chip is added into the board. Players win when he/she performs at least 4 consecutive chips in one or more horizontal, vertical, left diagonal, and right diagonal way.

Player

  • A class that represents the player’s data from database. For the sake of convenience, we did not provide the password for user.

ConnectFour

  • A game class that contains Board, ChipFactory, Player, and CheckStrategy. It will call method from other classes. Whenever the game is ended, it will update the score in database as well.  

Design Pattern

flyweight Flyweight Pattern - In ChipFactory Class

  • In each board, it contains many chips with almost no different except some of them differ only color and they consume a lot of memory. Therefore, we use flyweight pattern to store the chip that had already put (object created) in the board to HashMap. Then for each time we use that chip again, we can just retrieve it from HashMap without need to create it again. By doing this, it can help reducing the number of objects created as well as saving the memory used.

Null Object Pattern – In NullChip Class

  • This class will create dummy object instead of using null in order to avoid exception caused by null (e.g. NullPointerException.) We can check if it is NullChip by calling method isNull(). If it is true, then it is NullChip and vice versa.

Factory Pattern – In ChipFactory Class

  • Use with Chip Class to provide a way to create an object without exposing the creation logic to the client. Whenever we need the chip, we just call the ChipFactory class. If the chip is already created (stored in HashMap already), return that object to client. On the other hand, if it is not created, we create that new object, store in HashMap for further use and return object to client. Moreover, if the game has more chip in the future, we can just simply add more conditions to create another chip in ChipFactory Class.

temp c4 Stra Strategy Pattern – In CheckStrategy Class

  • This pattern provides a way to change the algorithm to check the winner during the runtime. In the future, if we have other ways to check for the winner (e.g. hard mode), we just change the value of CheckStrategy object. Then when we call getWinChipIndex() method it will perform the algorithm to check for the corresponding class.
Clone this wiki locally