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

MATLAB - Dependent properties and calculation
design pattern to use for changing object properties from property inspector
What are the types of inheritances?
State pattern, but controlled from 2 different places
Public static data used throughout program
Adding State in Decorator Pattern
What is the opposite of a base class in OOP?
Placement of service methods
Extensible Mapping design
Operator overloading and class definition in R: Use a different base field/corpus
Hybrid Functional/Object Oriented languages like F#/Scala: Use types with methods or methods and types [closed]
Good design pattern system rewrite?
Which design is a better? A singleton object or pass an object everytime? [closed]
Private vs Protected - Visibility Good-Practice Concern
matlab subsref: {} with string argument fails, why?
OO Pattern for GUI Builder

Categories

HOME
intellij-idea
service
mysqli
phantomjs
gaussian
arcgis
x86-64
ubuntu-14.04
snmp
kohana
gnuradio
country-codes
samsung-gear-s2
dcos
normals
jpql
osrm
email-attachments
tracking
cakephp-2.0
jinja2
lambda-calculus
openstack-horizon
openscad
ofbiz
glibc
bug-reporting
polybase
serenity-js
wai-aria
email-client
aws-iot
oracle-golden-gate
windows-mobile
mongoose-im
osgi-bundle
jbossfuse
edirectory
apm
akamai
visual-studio-debugging
microstrategy
tapply
delphi-xe
collation
php-mongodb
logan-square
ocamlbuild
opos
denodo
evaluation
beanshell
appcmd
kendo-scheduler
iban
catalyst
computed-properties
firebase-job-dispatcher
zsh-completion
objectify
vitamio
razorengine
phpdesigner
nugetgallery
hana-sql-script
dday
markerspiderfier
google-finance-api
gtkwave
kramdown
serial-communication
cyberduck
openhab
log-analysis
shunting-yard
jsonschema2pojo
reactjs-native
rda
sigma-grid-control
internet-radio
jfilechooser
mencoder
fade
windows-scheduler
magicsuggest
architectural-patterns
rbm
linqdatasource
rfc822
linear-interpolation
states
google-email-audit-api
github-archive
motorola-droid
facebook-winjs-sdk
zend-validate
flexbuilder
netduino
s60
nscharacterset
simultaneous
iphone-maps
data-formats
qlibrary





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