Last active
August 29, 2015 13:56
-
-
Save mallochine/9039926 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
class SomeParser { | |
parse(line) { | |
// Do some parsing work. | |
} | |
dataReady() { | |
// Easy way for others to figure out if the parser has data that's ready to be collected. | |
} | |
} | |
class SomeWorker { | |
handle(line) { | |
SomeParser.parse(line); | |
// For why dataReady() make good design, see Note 1. | |
if (SomeParser.dataReady()) { | |
data = SomeParser.getData(); | |
// Do some stuff with data. | |
} | |
} | |
finish() { | |
// Write this only if you want to print something out once | |
// your program is done reading from the stream. | |
} | |
// other helper functions here... | |
} | |
int main() { | |
while stdin.hasNextLine(): | |
SomeWorker.handle( stdin.nextLine() ); | |
// Only if you need to output additional data at the end of the stream. | |
SomeWorker.finish(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment