Here is something that I have came across in Scala that did not cause any problems in Java. Now I just do not know what is the right way of doing this in Scala.
Problem description: I have a Scala Object which denotes an 'abstract' object. It is intended to have a singletonic profile but it is not intended for real use, it is just a bunch of definitions common to it's children-singletons. So instead, I want to use it's children. So there comes the question: since I cannot inherit objects, should the common singleton functionality be realized as a class? As an abstract class? Trait does not suit me because it can't have constructors. If an abstract parent class would do, then how should I access it's singleton (or static) methods if I need them anythere? I realize that there might be a flaw in my design, but since I have this question and can't think of any definitive answer, it is interesting to hear what you say (including design alternatives).
It is my example of subroutines parsing. Does it correct way to do it? subrReserved is a list of subroutine names which are added to lexical.reserved.
abstract class Subroutine case class UserDefinedSubroutine(name: String, args: Option[List[Expression]]) extends Subroutine case class CDDSubr(args: Option[List[Expression]]) extends Subroutine case class CDTSubr(args: Option[List[Expression]]) extends Subroutine case class CFQSubr(args: Option[List[Expression]]) extends Subroutine case class DIETER_DATESubr(args: Option[List[Expression]]) extends Subroutine case class JULDATESubr(args: Option[List[Expression]]) extends Subroutine ... abstract class Statement case class Call(subr: Subroutine) extends Statement def getSubroutineByName(name: String, args: Option[List[Expression]]): Subroutine = name match { case "CDD" => CDDSubr(args) case "CDT" => CDTSubr(args) case "CFQ" => CFQSubr(args) case "DIETER.DATE" => DIETER_DATESubr(args) case "JULDATE" => JULDATESubr(args) ... case _ => UserDefinedSubroutine(name, args) } def callStmt: Parser[Statement] = "CALL" ~> subroutine ^^ Call def subroutine: Parser[Subroutine] = subroutineName ~ opt(argumentList) ^^ { case name~args => getSubroutineByName(name, args) } def subroutineName: Parser[String] = ( elem("subroutine name", subrname => (if (subrReserved contains subrname.chars) true else false )) ^^ (_.chars) | ident)
Recent comments
21 hours 27 min ago
10 weeks 3 days ago
15 weeks 6 days ago
17 weeks 2 days ago
20 weeks 4 days ago
42 weeks 1 day ago
47 weeks 6 days ago
50 weeks 5 days ago
1 year 44 weeks ago