Last active
August 29, 2015 14:17
-
-
Save laser/d0c798f6bbca1f3d9927 to your computer and use it in GitHub Desktop.
Putting the "Java" in "JavaScript"
This file contains hidden or 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
/* @flow */ | |
class User { | |
n: number; | |
constructor(n) { | |
this.n = n; | |
} | |
} | |
class UserDAOIFace { | |
getUserById(n): User { | |
throw new Error("Call me maybe (never)."); | |
} | |
} | |
class UserDAOImpl extends UserDAOIFace { | |
getUserById(n): User { | |
return new User(n); | |
} | |
} | |
class UserDAOTestImpl extends UserDAOIFace { | |
getUserById(n): User { | |
return new User(420); | |
} | |
} | |
class UserService { | |
dao: UserDAOIFace; | |
constructor(dao) { | |
this.dao = dao; | |
} | |
getUserById(x: number): User { | |
return this.dao.getUserById(x); | |
} | |
} | |
var u = new UserService(new UserDAOImpl()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment