TheLearningCurve / NutritionApiV3

0 stars 0 forks source link

We may not need to use singletons. If we do, we use enums. #3

Closed BrandonVanderMey closed 8 years ago

BrandonVanderMey commented 8 years ago

(Unfinished Issue: I got tired while researching. Will add more tomorrow.) Files: Main.java, SceneManager.java (possibly more files)

What you have done was great. It works very well. However, I came across some articles that say that the main benefit of using a singleton over just using a static class is that the singleton is able to implement interfaces. Unless you have a specific reason of needing a singleton over static, please comment.

If however we do need to use a singleton, there is a much better way: using Enums. If we use Enums, we make our application more thread-safe.

Helpful Links:

Difference Between Static and Singleton: http://stackoverflow.com/questions/519520/difference-between-static-class-and-singleton-pattern

What Enums Can Do: http://tutorials.jenkov.com/java/enums.html http://howtodoinjava.com/2012/12/07/guide-for-understanding-enum-in-java/

BrandonVanderMey commented 8 years ago

What was the reason of the SceneManager class?

KyletheWolff commented 8 years ago

The SceneManager originally was used to change between feature controllers and have access to the controllers without using static.

So now it does basically the same thing but now the only thing this will do is switch between the SignIn Scene and MainScene.

KyletheWolff commented 8 years ago

A singleton allows access to a single created instance - that instance (or rather, a reference to that instance) can be passed as a parameter to other methods, and treated as a normal object.

A static class allows only static methods.