Introducing models
A model is a domain object, which maps to database entities. For example, a social networking application has users. The users can register, update their profile, add friends, post links, and so on. Here, the user is a domain object and each user will have corresponding entries in the database. Therefore, we could define a user model in the following way:
case class User(id: Long, loginId: String, name: Option[String], dob: Option[Long]) object User { def register (loginId: String,...) = {…} ... }
Earlier, we defined a model without using a database:
case class Task(id: Int, name: String) object Task { private var taskList: List[Task] = List() def all: List[Task] = { taskList } def add(taskName: String) = { val lastId: Int = if (!taskList.isEmpty) taskList.last.id else 0 taskList = taskList ++ List(Task(lastId + 1, taskName)) } def delete(taskId: Int) = { taskList = taskList.filterNot(task =...