Introduction
The following article is a base class that can be used to develop a chess board application. The design of the application is based on the Abstract Factory Design Pattern.
Background
I wrote this article as an update to my previous article called "Easy to use ASP.NET Chessboard control". Many people complained that I did not use an Object Oriented approach - so, I've built this basic component framework now for anyone wanting to develop a chess board application.
Using the Code
The code makes use of the Abstract Factory pattern - I've built a main ChessFactory
class and then two other classes called WhiteChessFactory
and BlackChessFactory
that inherit from the ChessFactory
class. To display the concepts, I've built a very basic Windows app that asks the user if he wants the white or black pieces. (Please note that the actual chess board application has still not been added - this is just the basic class structure of the application.)
Public MustInherit Class ChessFactory
Public MustOverride Function CreateKing() As King
Public MustOverride Function CreateQueen() As Queen
Public MustOverride Function CreateRook() As Rook
Public MustOverride Function CreateBishop() As Bishop
Public MustOverride Function CreateKnight() As Knight
Public MustOverride Function CreatePawn() As Pawn
End Class
Public Class WhiteChessFactory : Inherits ChessFactory
Public Overrides Function CreateKing() As King
Return New WhiteKing()
End Function
Public Overrides Function CreateQueen() As Queen
Return New WhiteQueen()
End Function
Public Overrides Function CreateRook() As Rook
Return New WhiteRook()
End Function
Public Overrides Function CreateBishop() As Bishop
Return New WhiteBishop()
End Function
Public Overrides Function CreateKnight() As Knight
Return New WhiteKnight()
End Function
Public Overrides Function CreatePawn() As Pawn
Return New WhitePawn()
End Function
End Class
For each of the chess pieces, a separate class has then be created.
Points of Interest
The chess class design has provided an interface for creating families or related or dependent objects without specifying their concrete classes.
History
If anyone is interested in adding some additional functionality to the classes to build the actual chess application, then email me at louwgi@avusa.co.za.