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

Se feedback 6 #125

Merged
merged 4 commits into from Jun 8, 2016
Merged

Se feedback 6 #125

merged 4 commits into from Jun 8, 2016

Conversation

ghost
Copy link

@ghost ghost commented Jun 4, 2016

Questions, Comments - both are welcome. Have a good weekend

@thervh70 thervh70 added the review label Jun 4, 2016
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.337% when pulling a7e3cfe on se_feedback_6 into 344421c on master.

* 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?
Copy link
Collaborator

@mpsijm mpsijm Jun 6, 2016

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.

Copy link
Author

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

Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator

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).

Copy link
Author

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.

@mpsijm
Copy link
Collaborator

mpsijm commented Jun 8, 2016

I think this can be merged now. Who else agrees?

@MathiasMeuleman
Copy link
Collaborator

Yes, will merge

@MathiasMeuleman MathiasMeuleman merged commit d8ad96b into master Jun 8, 2016
@MathiasMeuleman MathiasMeuleman deleted the se_feedback_6 branch June 8, 2016 12:10
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

Successfully merging this pull request may close these issues.

None yet

4 participants