Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueueProvider rework suggestion #258

Open
Ronan-H opened this issue May 27, 2019 · 3 comments
Open

QueueProvider rework suggestion #258

Ronan-H opened this issue May 27, 2019 · 3 comments

Comments

@Ronan-H
Copy link

Ronan-H commented May 27, 2019

As I was talking about in #196, I've been trying to figure out how to write JUnit tests for the menu classes. Without changing QueueProvider, I'd have to use System.setIn/setOut to test the menus.

Looking at QueueProvider, I'm thinking it would maybe work better as a singleton, and then a small hierarchy of QueueProvider like classes - a base, abstract class (or interface?) QueueProvider, with subclasses like TestingQueueProvider for testing, and other subclasses for standalone and server/client QueueProviders.

startMessenger() would then create the singleton instance variable in QueueProvider, which would be accessed with QueueProvider.getInstance() to use offer() and take() as before, or maybe getQueueProvider() which could be statically imported to make things a bit cleaner.

So that would make testing with the QueueProvider a lot cleaner (since you'd be overriding take() and offer() to store output etc) and also mean you don't need things like if (GameModeType.SERVER == mode)... in QueueProvider.

Just an idea. Is that too much?

@paddatrapper
Copy link
Contributor

This is definitely the way to go. Supports clean code and makes testing much easier. getInstance() is probably the better choice as it matches where else we use singletons (or at least is consistent with other projects I work on)

@Ronan-H
Copy link
Author

Ronan-H commented Jun 11, 2019

Some things I was wondering while starting the rework:

  • Is using GameModeType necessary anymore for QueueProvider? Is it needed much elsewhere?
  • Between SERVER and CLIENT, which side uses QueueProvider? I'm pretty confused about the server/client relationship in general...

@paddatrapper
Copy link
Contributor

Is using GameModeType necessary anymore for QueueProvider? Is it needed much elsewhere?

It isn't needed if QueueProvider is refactored.

Between SERVER and CLIENT, which side uses QueueProvider? I'm pretty confused about the server/client relationship in general...

The QueueProvider is mostly used in stand-alone games. The client/server connection is managed in Client and JAdventure. The QueueProvider is used to send messages from the server to the client, with the game logic happening on the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants