0

I'm currently creating an implementation of draw poker in Java.

It's eventually going to be made playable through twitter, allowing people to play a game against bots by messaging the profile, but right now I just want to get a console implementation working first.

Basically, I'm thinking of having a class called HandOfPoker to facilitate the proceedings of a single hand (betting, discarding cards, betting again, showing cards, determining winner, etc.) and then another class GameOfPoker to facilitate multiple instances of HandOfPoker.

With this structure, I'm thinking that I'm going to have to produce console output within HandOfPoker or GameOfPoker, letting the player know what's happening. For some reason, I have it in my head that its bad OOP design to produce console output using System.out.print() or System.out.println() anywhere other than the Main method - is this true?

screeb
  • 625
  • 6
  • 20
  • your question might pretty much be answered by the following answer: http://stackoverflow.com/a/2750367/3858121 – Japu_D_Cret Mar 23 '17 at 12:46
  • @Japu_D_Cret I think this case is different: the console is used to interact with the user, not to log stuff like in the question you linked. – assylias Mar 23 '17 at 12:47
  • Ideally you would create some kind of interface, e.g. IOutput, which has the single method `write()` or something. You then implement this in your Main class and call it where you want to write some output, meaning you can change where output goes in one place. – Steve Smith Mar 23 '17 at 12:53
  • @Japu_D_Cret Yeah, as assylias said, I'll be using the console to take input (what cards to discard, whether to continue playing) and notify the user of the other players' actions, etc. – screeb Mar 23 '17 at 12:59
  • @SteveSmith would this approach also work for if I was taking input in from the user aswell? In general, is it bad design to have any console input/output anywhere other than the main method? – screeb Mar 23 '17 at 13:01
  • "is it bad design to have any console input/output anywhere other than the main method?" I've never heard that. What is special about the main method? Nothing. – Steve Smith Mar 23 '17 at 13:11

1 Answers1

0

Your intuition would be right. The way I see it now, you have two different classes "facilitating the game". Although the HandOfPoker class is specific to a hand, and the GameOfPoker class is specific to a game, they are both doing the same job of interacting with the user. You could further modularize by saying that GameOfPoker does all the console output and user interaction, consulting GameOfPoker for the information it needs to do that job. This would help you with debugging in that you wouldn't have to find out which class is outputting a given message, and it gives both classes more specific jobs to do instead of intersecting on each others territory, so to speak.