Skip to content

Instantly share code, notes, and snippets.

@ugdark
Created November 12, 2014 05:17
Show Gist options
  • Save ugdark/e5c2acbbec0845f704fb to your computer and use it in GitHub Desktop.
Save ugdark/e5c2acbbec0845f704fb to your computer and use it in GitHub Desktop.
実体とはとか振る舞いとかその辺りのサンプル。。。
import org.sisioh.dddbase.core.model.{Entity, Identifier}
import org.specs2.mutable.Specification
class EntitySpec extends Specification {
case class ManId(value: Long)
extends Identifier[Long]
trait Man extends Entity[ManId] {
val name: String
val age: Int
val married: Boolean
}
object ManRepository {
private case class ManImpl(
override val identifier: ManId,
override val name: String,
override val age: Int,
override val married: Boolean
) extends Man {
}
private case class NishiyamaManImpl(
override val identifier: ManId,
override val name: String,
override val age: Int
) extends Man {
override val married: Boolean = false
val danger: Boolean = true
}
// def entry(identifier: ManId, name: String, age: Int): Man = new ManImpl(identifier, name, age)
def entry(manId: ManId, name: String, age: Int, married: Boolean): Man = {
if (name == "nishiyama") {
// 西山なら結婚できない そして危険である
new NishiyamaManImpl(manId, name, age)
} else {
new ManImpl(manId, name, age, married)
}
}
}
// お試しコードのため
// args(skipAll = true)
"Entityを" should {
"試す" in {
// 男として振る舞えるが西山としての実体を保つ これは外からは見えない
val nishiyama: Man = ManRepository.entry(ManId(12L), "nishiyama", 35, true)
// 男として振る舞えるが西山としての実体を保つ これは外からは見えない
val kato: Man = ManRepository.entry(ManId(12L), "kato", 25, false)
println("test:[" + nishiyama + "]")
"" must be("")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment