• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OO Design for Deck class (Card holder)

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've decided to go over some old code I wrote to make it a lot more OO friendly but am having trouble with two classes in particular which are extremely similar but also quite different:



The problem I have is that PlayingDeck is the standard deck we all know and love when playing card games such as Poker etc. ShreddedDeck is a deck which will be populated with cards which have been discarded from the PlayingDeck. That is why the implementation of the addCard() and removeCard() is different, the constructor is also different between these classes. Nevertheless, these classes are quite similar so should I add/is there scope for say an interface or an abstract class somewhere?
I was thinking about a Deck Interface with the methods add(), remove(), size() but decks are also shuffled but the shreddedDeck() should never be shuffled.
Any advice/input would be welcome.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Faz Ali
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jimmy Clark wrote:



This is a similar design I came up with but the problem is the shuffle() method which is not something that a ShreddedPlayingCardDeck should have therefore should not be a part of its API which it will be when implementing that interface.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ShreddedPlayingCardDeckImpl would not have an implementation for a shuffle() method. There are numerous ways to code shuffle() to prevent it from operating in specific conditions. There are many factors to take into consideration when designing an OO application and many decisions have to be made, big ones and trivial ones.
 
I'm still in control here. LOOK at this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic