Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
1) Users will play the chess game on 8x8 chess board
2) ChessBoard will have different pices like king, queen,rook, bishop,knight and pawn
3)Maintain the history of the moves
Determine how these objects will interact with each other to fulfill the use cases...
Account Class- > We will declare an account class which Users and amdin class will inherit
User class -> User class will inherit the account class and will have user releated functionality
Admin class -> Admin class will perfrom admin related functions
GameBoard -> This will have attributes like pieces color pieces of each user
Piece -> Each GameBoard will have different pieces for each set of users
Game -> Each Game will contain game Board and also id of the players
Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...
Account Class- > We will declare an account class which Users and amdin class will inherit
User class -> User class will inherit the account class and will have user releated functionality
Admin class -> Admin class will perfrom admin related functions
GameBoard -> This will have attributes like pieces color pieces of each user
Piece -> Each GameBoard will have different pieces for each set of users
Game -> Each Game will contain game Board and also id of the players
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
We will be using factory pattern for pieces whether the piece is king, queen,rook and others
For creating user and admin we have also used factory pattern
For informing user Regarding player turn we will be using observer pattern
Attributes: For each class, define the attributes (data) it will hold...
Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
package models;
public abstract class Account
{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package models;
import java.util.Stack;
public class Game
{
private User player1;
private User player2;
private GameBoard gameBoard;
private Stack<Move>player1Moves=new Stack<>();
private Stack<Move>player2Moves=new Stack<>();
String player1Color="";
String player2Color="";
public Game(User player1, User player2, GameBoard gameBoard, String player1Color, String player2Color) {
this.player1 = player1;
this.player2 = player2;
this.gameBoard = gameBoard;
this.player1Color = player1Color;
this.player2Color = player2Color;
}
public GameBoard getGameBoard() {
return gameBoard;
}
public void setGameBoard(GameBoard gameBoard) {
this.gameBoard = gameBoard;
}
public Stack<Move> getPlayer1Moves() {
return player1Moves;
}
public void setPlayer1Moves(Stack<Move> player1Moves) {
this.player1Moves = player1Moves;
}
public Stack<Move> getPlayer2Moves() {
return player2Moves;
}
public void setPlayer2Moves(Stack<Move> player2Moves) {
this.player2Moves = player2Moves;
}
public String getPlayer1Color() {
return player1Color;
}
public void setPlayer1Color(String player1Color) {
this.player1Color = player1Color;
}
public String getPlayer2Color() {
return player2Color;
}
public void setPlayer2Color(String player2Color) {
this.player2Color = player2Color;
}
public User getPlayer1() {
return player1;
}
public void setPlayer1(User player1) {
this.player1 = player1;
}
public User getPlayer2() {
return player2;
}
public void setPlayer2(User player2) {
this.player2 = player2;
}
}
package models;
import java.io.PipedReader;
import java.util.List;
public class GameBoard
{
Piece gameBoard[][];
GameBoard()
{
gameBoard=new Piece[8][ 8];
}
void initializeGameBoard()
{
}
}
package models;
public class Move
{
Piece currPiece;
int startRow;
int startCol;
int endRow;
int endCol;
public Move(Piece currPiece, int startRow, int startCol, int endRow, int endCol) {
this.currPiece = currPiece;
this.startRow = startRow;
this.startCol = startCol;
this.endRow = endRow;
this.endCol = endCol;
}
public Piece getCurrPiece() {
return currPiece;
}
public void setCurrPiece(Piece currPiece) {
this.currPiece = currPiece;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public int getStartCol() {
return startCol;
}
public void setStartCol(int startCol) {
this.startCol = startCol;
}
public int getEndRow() {
return endRow;
}
public void setEndRow(int endRow) {
this.endRow = endRow;
}
public int getEndCol() {
return endCol;
}
public void setEndCol(int endCol) {
this.endCol = endCol;
}
}
package models;
public abstract class Piece
{
abstract void move();
}
package models;
public class Rook extends Piece
{
String color;
int row;
int col;
public Rook(String color, int row, int col) {
this.color = color;
this.row = row;
this.col = col;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getCol() {
return col;
}
public void setCol(int col) {
this.col = col;
}
@Override
void move() {
}
}
package models;
import java.util.ArrayList;
import java.util.List;
public class User extends Account
{
List<Game> gamesList=new ArrayList<>();
Game currGame;
public List<Game> getGamesList() {
return gamesList;
}
public void setGamesList(List<Game> gamesList) {
this.gamesList = gamesList;
}
public Game getCurrGame() {
return currGame;
}
public void setCurrGame(Game currGame) {
this.currGame = currGame;
}
}
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Single Responsibility Principle -> Each class is responsible for only one functionality
Open closed principle -> All the classes are open for extension while closed for modifications
LisKov SubStitution -> Child classes like user and account can be substituted in place of parent class
Interface Segration Principle - The following code has not used any interfaces
Dependency injection principle -> Following code has not used any depnedency injection principle
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
As we have defined pieces as abstract class so it can be easily extended for other sub classes .
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Added class Diagram
Critically examine your design for any flaws or areas for future improvement...