oop


Players and deck methods in a card game


I'm programming a card game (of Uno / Mau Mau type) and I have this design problem:
The deck contains two stacks of cards, one of them shows faces, the other shows backs. When a game is in progress and a player throws a card, it should go onto the "faces" stack. However, when the game is finished, the cards of the last player should go back onto the "backs" stack.
1) Should the deck have two methods for adding cards (addToFacesStack and addToBacksStack)
or
2) Should the deck have an addCards method and decide itself which stack the cards should go onto (the deck would have to know the state of the game - in progress/finished)?
Also, when the game is in progress and a player (who knows the rules and selects cards to play accordingly) throws card(s) onto the "faces" stack, should the deck "re-check" whether the player's move is valid?
Thanks in advance for your suggestions!
Caroline
I think you should be asking the question: should the model know about the game logic or just the state of the game?
If YES, then you need to include the game logic inside your model, hence you can have only the addCards method, and the Deck will decide where to add the card(s). But, in this case the game model and game logic are tightly coupled. If you were to use the same model for another variation of the game (with a different logic), this option would not be appropriate.
If NO, then you can follow the Boundary - Control - Entity design pattern. Here, you need to have separate methods for adding cards to the first or second stack. And encode the game logic into your controller objects, which would know the rules of the game. Using this pattern, you can reuse the same model and just employ different controllers based on the game being played.
Regarding your question:
Also, when the game is in progress and a player (who knows the rules and selects cards to play accordingly) throws card(s) onto the "faces" stack, should the deck "re-check" whether the player's move is valid?
In this case, you can have a controller that will check whether the move is valid or not. No need to encode the logic inside the model.

Related Links

Isn't polymorphism just a side effect of inheritance?
Overriding method to create a subclass
How to model the opening times of shops in an object oriented way?
Excel VBA Class Property returning a public long variable, but not a public string variable
Always Valid Entities
List object methods in Common Lisp (CLOS)
How to represent a unit as a point in pharo?
Separate controllers for child entities
Lua OOP grid class with event
Function returns nil when called inside constructor
How to structure object: OOP, composition
Can abstract factory be used for something other than creation
What is the best description for Encapsulation to give in an interveiw?
lua oop how to call superclass constructor
What does “model” actual mean in the context of rich domain models and anemic domain models?
OOAD Design for furniture and testing [closed]

Categories

HOME
oop
ide
ssh
cluster-analysis
dronekit
xamarin.forms
postsharp
app-store
opengl-es
gnuradio
pdf-generation
olap
desktop-application
http-status-codes
camunda
luis
facebook-marketing-api
ringcentral
virtuemart
keystone
descriptor
bug-reporting
angular2-pipe
pushbullet
oracle-golden-gate
bootstrap-accordion
visual-studio-community
javapns
ds-5
delphi-2010
login-required
postgresql-9.6
snapkit
gitosis
powerbi-embedded
tunnel
ansible-inventory
mkdir
extern
nscollectionview
mockserver
gem-fury
pyexcel
definition
paperclip
cakephp-3.2
taleo
azure-data-catalog
spring-data-commons
rivets.js
ng-class
dcom
jcifs
photoshop-script
easy68k
alfred
hoare-logic
cherry-pick
nsoperationqueue
database-administration
stdlist
abstract
oryx
markerspiderfier
angular-promise
jts
personality-insights
traminer
vanilla-forums
autoscaling
nmock
gcc-warning
mergecursor
asp.net-2.0
backtrace
method-overloading
frisby.js
report-builder2.0
qf-test
oxygenxml
dotcmis
object-oriented-database
infor-eam
starling-framework
lastinsertid
jfilechooser
raddatepicker
forward-declaration
system.transactions
metapost
webpage-screenshot
states
certificate-revocation
google-email-audit-api
sup
dancer
socketasynceventargs
helicontech
copyfile
visual-leak-detector
hwnd
designated-initializer
moss2007-security
miniport
web-search

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App