Skip to content

Instantly share code, notes, and snippets.

@jonvuri
Last active March 8, 2016 20:33
Show Gist options
  • Save jonvuri/08e8cf8f83888d5c75e6 to your computer and use it in GitHub Desktop.
Save jonvuri/08e8cf8f83888d5c75e6 to your computer and use it in GitHub Desktop.
case class Context(local: Boolean)
trait FileSource {
def readFile(location: String): String
def writeFile(location: String, content: String): Unit
}
object FileSource {
def apply(context: Context): FileSource {
if (context.local) new LocalFileSource(context) else new ExternalFileSource(context)
}
}
class LocalFileSource(context: Context) extends FileSource {
// implementation
}
class ExternalFileSource(context: Context) extends FileSource {
// implementation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment