使用抽象工厂设计模式的国际象棋应用程序类设计(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/chess-application-class-design-using-the-abstract-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1068 个词 阅读量 0使用抽象工厂设计模式的国际象棋应用程序类设计(译文)
原文地址:https://www.codeproject.com/Articles/27871/Chess-Application-Class-Design-Using-the-Abstract
原文作者:Louwgi
译文由本站 robot-v1.0 翻译
前言
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 “) 易于使用的ASP.NET Chessboard控件(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)
该代码利用了Abstract Factory模式-我已经建立了一个主(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
类.为了显示这些概念,我构建了一个非常基本的Windows应用程序,询问用户是否需要白色或黑色的碎片. (请注意,实际的国际象棋棋盘应用程序尚未添加-这只是该应用程序的基本类结构.)(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(louwgi@avusa.co.za).(.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VB VB9.0 .NET3.0 .NET3.5 .NET .NET2.0 Dev 新闻 翻译