Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / Visual Basic

Chess Application Class Design Using the Abstract Factory Design Pattern

Rate me:
Please Sign up or sign in to vote.
1.29/5 (5 votes)
17 Jul 2008CPOL1 min read 32.4K   407   8   4
A class design using the Abstract Factory Design Pattern for a chess application.

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.)

VB
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
South Africa South Africa
Gideon Louw is a qualified MCSD and software professional.

He developed several industrial and government related applications that has successfully been installed all over the world.

Comments and Discussions

 
GeneralMy vote of 1 Pin
steblublu27-Jun-09 10:01
steblublu27-Jun-09 10:01 
GeneralJust a question Pin
ednrg17-Jul-08 5:39
ednrg17-Jul-08 5:39 
GeneralAnother approach Pin
RugbyLeague17-Jul-08 3:43
RugbyLeague17-Jul-08 3:43 
GeneralRe: Another approach Pin
Louwgi17-Jul-08 19:09
Louwgi17-Jul-08 19:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.