Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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.
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic