Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.72 KB | None | 0 0
  1. /**
  2.   * Created by ania on 23.04.17.
  3.   */
  4.  
  5. object Application {
  6.   def main(args: Array[String]): Unit = {
  7.     var plik = "test.json"
  8.     var strategy : Parser = null
  9.     plik.split("\\.").last match {
  10.       case "json" => strategy = new JsonParser()
  11.       case "csv" => strategy = new CSVParser()
  12.       case _ | null => throw new IllegalArgumentException("Not supported extension")
  13.     }
  14.     strategy.parse()
  15.   }
  16. }
  17.  
  18. trait Parser {
  19.  
  20.   def algorithm()
  21.  
  22.   def parse(): Unit = {
  23.     algorithm()
  24.   }
  25. }
  26.  
  27. class CSVParser() extends Parser {
  28.   override def algorithm: Unit = {
  29.     print("Parsuje CSV")
  30.   }
  31. }
  32.  
  33. class JsonParser() extends Parser {
  34.   override def algorithm(): Unit = {
  35.     print("Parsuje JSON")
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement