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

SpriteStore should be singletone XOR abstract class #9

Open
AKryukov92 opened this issue Jun 20, 2017 · 2 comments
Open

SpriteStore should be singletone XOR abstract class #9

AKryukov92 opened this issue Jun 20, 2017 · 2 comments

Comments

@AKryukov92
Copy link
Contributor

If class is abstract, then it is can have multiple childrens. Assuming that singletone should be instantiated only once, then this situation doesn't make sense.
In addition AwtSpriteStore has public constructor which ruins the idea of singletonius SpriteStore.
I think of several solutions of this problem:

  1. Do not use Singletone pattern, instantiate SpriteStore in main(String[] args) and pass its instance to all classes that use SpriteStore. For small classes like Player it is good idea to pass Sprites to constructor.
  2. Merge classes SpriteStore and AwtSpriteStore to single class. This option is suitable for using singletone pattern.
@LordStephen77
Copy link
Member

This project was born as a study material, initially it was much simpler.

I've read everything and what I see you know about Java. I would opt for the second option, what do you suggest to do? It would be best to divide the code into multiple classes by avoiding single classes with 1000 and over lines of code (for ease of reading and editing).

I did my best to make the project simple, so my choice definitely falls on the organization of several classes tied to a specific package in the project. This makes the structure easier to understand and keep code in the future will be less complex.

I hope I do not look too beginner (I am). Thank you.

@AKryukov92
Copy link
Contributor Author

You did a great job making first step. You don't look too beginner for me. You understand basic concepts and use them. I like the idea of keeping this project a study material. Thats why I explain those issues here. It is important that everyone understand why any change has been made.

Class with 1000 lines of code is not bad if it is used for single purpose (cohensive). But when you feel, that code in the class is used for multiple purposes, then you need to think about making another class.
When you feel that a number of classes are used together more often, then you might want to make package.

I prefer 1 solution because it makes use of SpriteStore obvious. Currently all references to SpriteStore are hidden and spread across whole project. This phenomenon is called high coupling.

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