are domain objects whose identity is NOT defined by their attributes
are objects that ARE defined by their attributes
// Entity class User { private $id; // could have used SSN, if it was available private $name; private $address; public function changeName($newName) { $this->name = $newName; } public function changeAddress($newAddress) { $this->address = $newAddress; } } // Value Object class Name { private $firstName; private $lastName; } // Value Object class Address { private $street; private $city; private $state; private $zip }
interface Repository { function getById($id); function save($entity); } class MySqlRepository implements Repository { function getById($id) { /* query real MySQL database */ } function save($entity) { /* insert data into real MySQL database */ } } class InMemoryRepository implements Repository { private $db; // array of id to entity function getById($id) { /* query $db */ } function save($entity) { /* mutate $db */ } }
are objects that
class OpenEnrollment(oeRepo: Repository[OpenEnrollment], titanClient: TitanClient) { def edit(oeId: UUID, startDate: Instant, endDate: Instant): Future[Unit] = { for { // In Future // get the OE domain object oe <- oeRepo.getById(oeID) // edit the OE editedOe <- editOpenEnrollent(oe, startDate, endDate) // save it _ <- oeRepo.save(editedOe) // conditionally "run" it _ <- if (editedOe.status === OpenEnrollmentState.Ready) runOpenEnrollment(editedOe) else Future.successful(()) } yield () } def runOpenEnrollment(oe: OpenEnrollment): Future[Unit] = { ... } }