Skip to content

Room domain model: value or entity? #14

@4441564944

Description

@4441564944

If I understand it well, the Room domain model is what Domain-Driven Design (DDD) call Entity / Aggregate root entity, I think it would be better to compare rooms by id only because e.g. the price can change but the room is the same. At this moment the room is represented as a value object (DDD). I would model it like this:

Size =  NewType("Size", int)
Price = NewType("Price", Decimal)
Address = NewType("Address", str)
Description = NewType("Description", str)

class Room:
    """
    An aggregate root entity.
    """
    def __init__(self, id: UUID, size: Size, price: Price, address: Address, description: Description) -> None:
        self.id = id
        self.size = size
        self.price = price
        self.address = address
        self.description = description

    def __eq__(self, that) -> bool:
        return all((isinstance(that, type(self)), self.id == that.id))

    def __hash__(self) -> int:
        return hash((type(self), self.id))

    @classmethod
    def make(cls, id: UUID, size: Size, price: Price, address: Address, description: Description) -> Room:
        return cls(id, size, price, address, description)

Is there some channel where this architectural decisions can be discussed?

All the best, David.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions