Click here to Skip to main content
Licence CPOL
First Posted 17 Jul 2008
Views 12,702
Downloads 167
Bookmarked 8 times

Chess Application Class Design Using the Abstract Factory Design Pattern

By | 17 Jul 2008 | Article
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.)

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)

About the Author

Louwgi

Web Developer

South Africa South Africa

Member

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.


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmembersteblublu10:01 27 Jun '09  
GeneralJust a question Pinmemberednrg5:39 17 Jul '08  
GeneralAnother approach PinmemberRugbyLeague3:43 17 Jul '08  
GeneralRe: Another approach PinmemberLouwgi19:09 17 Jul '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 17 Jul 2008
Article Copyright 2008 by Louwgi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid