This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
A singleton is the one and only possible instance of a Class. In languages like Java you have to use | |
all kinds of crazy patterns to accomplish this. | |
See http://en.wikipedia.org/wiki/Singleton_pattern | |
Not so in Ceylon however :) You just need to use an algebraic type with a single subtype (object) | |
**/ | |
shared abstract class Earth() of earth {} | |
shared object earth extends Earth(){} | |
//WON'T COMPILE ==> not a subtype of any case of enumerated supertype: BabyEarth is a subtype of Earth | |
//class BabyEarth() extends Earth() {} | |
//WON'T COMPILE ==> not a subtype of any case of enumerated supertype: BabyEarth is a subtype of Earth | |
//shared object babyEarth extends Earth() {} |
No comments:
Post a Comment