-
-
Save le0nidas/096c9cc9065a226768072eece1df50c7 to your computer and use it in GitHub Desktop.
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
interface History { | |
fun push(url: URL) | |
fun pop(): URL | |
fun peek(): URL | |
} | |
class Browser( | |
private val history: History | |
) { | |
var activeURL: URL? = null | |
private set | |
fun visit(url: URL) { | |
activeURL = if (url == URL("http://default")) | |
history.peek() else | |
url | |
history.push(activeURL!!) | |
} | |
fun back() { | |
history.pop() | |
activeURL = history.peek() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment