User:Douglas Wall

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Add problems for Cards 1 design)
m (Correction)
Line 19: Line 19:
 
*There seems to be a need for a Strategy pattern in here, around ''ValueCard'' and its subclasses and possibly including the joker in some rework of the structure.
 
*There seems to be a need for a Strategy pattern in here, around ''ValueCard'' and its subclasses and possibly including the joker in some rework of the structure.
  
*It is seems huge and unnecessarily complex for something that should be simple. See number 2.
+
*It is seems huge and unnecessarily complex for something that should be simple. See above.

Revision as of 02:05, 4 August 2009

Coming soon, some sort of design project decision, for the mean time I shall consider the cards problem.














Cards as a minor design study (project warm-up)

Someone asked me this question after they were asked it in a job interview: "Can you draw a UML diagram for a deck of cards including the Jokers". Sounds simple right? Well after my mind imploded while trying to deal with the Joker (no pun intended), which complicates everything, I have resolved to try and crack that nut in an OO manner. I have a loose context for the design, that being that it must be reasonably extendible/reusable and easily maintained. It should feature no game specific behaviour, and I will probably ignore graphic representation entirely.

Disclaimer: I make no claim to know what I am doing. Most diagrams will be missing details. Some may even cause dysentery.

Naturally, the solution could be as simple, yet horrific as this: Bad Cards.jpg

To start with I have constructed an inheritance monster:

Cards 1.jpg

Problems:

  • What does the abstract class Card actually contribute to its subclasses? If I ignore physical details (dimensions, materials etc) and visual items (symbols, images, colour) then there appears to be nothing else significant that it can have. The same thing applies to the Joker. The Joker card itself has no specific methods or fields that I can depict, a joker is simply a particular card with no suit or value. This problem also affects most of the other objects.
  • There seems to be a need for a Strategy pattern in here, around ValueCard and its subclasses and possibly including the joker in some rework of the structure.
  • It is seems huge and unnecessarily complex for something that should be simple. See above.
Personal tools