Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by ania on 23.04.17.
- */
- object Application {
- def main(args: Array[String]): Unit = {
- var plik = "test.json"
- var strategy : Parser = null
- plik.split("\\.").last match {
- case "json" => strategy = new JsonParser()
- case "csv" => strategy = new CSVParser()
- case _ | null => throw new IllegalArgumentException("Not supported extension")
- }
- strategy.parse()
- }
- }
- trait Parser {
- def algorithm()
- def parse(): Unit = {
- algorithm()
- }
- }
- class CSVParser() extends Parser {
- override def algorithm: Unit = {
- print("Parsuje CSV")
- }
- }
- class JsonParser() extends Parser {
- override def algorithm(): Unit = {
- print("Parsuje JSON")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement