Ideally, you shouldn't be extending a concrete class, and especially not a case class! Given that there's no potential to customise SUCCESS_MESSAGE and FAILURE_MESSAGE you probably also want to make these singletons Finally, underscores are a Bad Thing(tm) in Scala variable or class names. All UPPERCASE names are not idiomatic either.So: sealed trait Message case object SuccessMessage extends Message case object FailureMessage extends Message def log(str: String, msgType: Message) = msgType match { case SuccessMessage => println("Success: " + str) case FailureMessage => println("Failure: " + str) } Alternatively, and I would recommend this, you can wrap the actual message string: sealed trait Message { def msg: String } case class Success(msg:String) extends Message case class Failure(msg:String) extends Message def log(msg: Message) = msg match { case Success(str) => println("Success: " + str) case Failure(str) => println("Failure: " + str) }.
Ideally, you shouldn't be extending a concrete class, and especially not a case class! Given that there's no potential to customise SUCCESS_MESSAGE and FAILURE_MESSAGE, you probably also want to make these singletons. Finally, underscores are a Bad Thing(tm) in Scala variable or class names.
All UPPERCASE names are not idiomatic either. So: sealed trait Message case object SuccessMessage extends Message case object FailureMessage extends Message def log(str: String, msgType: Message) = msgType match { case SuccessMessage => println("Success: " + str) case FailureMessage => println("Failure: " + str) } Alternatively, and I would recommend this, you can wrap the actual message string: sealed trait Message { def msg: String } case class Success(msg:String) extends Message case class Failure(msg:String) extends Message def log(msg: Message) = msg match { case Success(str) => println("Success: " + str) case Failure(str) => println("Failure: " + str) }.
1 +1 for complete code review. :-) – missingfaktor Oct 25 '10 at 14:06 s/in Scala variable names/in Scala class names/ – Alexey Romanov Oct 25 '10 at 14:46 variable OR class names, if you want to be exact :) – Kevin Wright Oct 25 '10 at 14:49 thanks for all the info and advice! – stephanos Oct 25 '10 at 16:58 1 The first example still suffers the same problem, since Message is not marked abstract.
The second example is ok because the abstract method msg guarantees that Message is abstract as well. – Daniel C. Sobral Oct 25 '10 at 21:23.
You missed one case: The message might be an instance of MESSAGE, not one of its subclasses. If you want to make this case impossible, you need to make MESSAGE abstract. This will make the warning go away.
Thanks - this fixed it :) yet Kevin's solution seemed 'purer' – stephanos Oct 25 '10 at 16:57.
Finally, underscores are a Bad Thing(tm) in Scala variable or class names. All UPPERCASE names are not idiomatic either.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.