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
Se feedback 6 #125
Se feedback 6 #125
Conversation
* contain identical code except for the type value, include the type in the event and pass a generic Event | ||
* makes the switch in the `MainController` smaller as well | ||
* `URLHandler` | ||
* contains only public static functions but isn't singleton? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breijm URLHandler
does not maintain state. We made it an abstract utility class, much like the Math
class in Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Java Math class is a final class (not abstract) and a Singleton. Please see http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Math.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, but in Typescript one cannot be final (see this issue). And the Math
class is not really a Singleton since it cannot be instantiated at all, just like our URLHandler
. The only difference is that our URLHandler
can be subclassed since Typescript does not allow the final
keyword.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a language deficiency that will be fixed in TS 2. In general, singletons should not be open to subclassing since you cannot guarentee that the subclasses will also be Singleton.
Singleton simply means that there is one such entity. In the Math example, it means that every Math.xxxx call or attribute always refers to the same Math entity. You cannot create more because of the final class and private constructor.
Does that also mean that the other Singletons you have in your system also allow subclassing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the other singletons do not allow subclassing. I just tried compiling class SubStatus extends Status { }
, which fails because the classname Status
is shadowed by the global variable Status
because of the special Singleton construction we use (var Status = new (class Status { ... })();
, see this StackOverflow answer).
To get back to why URLHandler
is not a Singleton, I have thought of another reason. In general, a method that does not use instance variables, can be static (or at least WebStorm tells me so). As none of the methods in URLHandler
use instance variables, they can all be static. In case you agree with me, I'll add a comment to this class that URLHandler
should be final, but Typescript does not support this yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, with "Math entity" you mean the class? Because Math
itself is not an instance you can pass around to other classes (something you can do with Singletons).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok good that your other classes do not have this problem.
With regards to the "is it a Singleton or not" discussion, I agree you should add the comment and I'm willing to agree to disagree what it's exactly called; there are more important things to do.
I think this can be merged now. Who else agrees? |
Yes, will merge |
Questions, Comments - both are welcome. Have a good weekend