DDD entity
Project description
dddentity
DDD entity.
Usage
from dddentity import Entity, ref
UserId = str
class User(Entity[UserId]):
def __init__(self, id: UserId, name: str) -> None:
self.id = id
self.name = name
def _ref_(self) -> UserId:
return self.id
assert User("0001", "Gilgamesh") == User("0001", "Bilgamesh")
assert ref(User("0002", "Enkidu")) == "0002"
Caveat
Currently eq=False must be set when using with dataclasses
to prevent to generate __eq__() method by dataclass.
@dataclass(eq=False)
class User(Entity[UserId]):
...
API
Module dddentity
abstract class Entity[T]
Entity class.
Classes implementing this class must implement abstract method _ref_().
This class is hashable, satisfying the following conditions:
entity1 == entity2iffentity1._ref_() == entity2._ref_()hash(entity) == hash(entity._ref_())
where entity, entity1, entity2 are entities.
type parameter T
Type of the identifier of the entity, which must be hashable.
abstract method _ref_() -> T
Shall return the identifier of the entity.
function ref(entity: Entity[T]) -> T
Return entity._ref_().
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dddentity-0.1.0.tar.gz.
File metadata
- Download URL: dddentity-0.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.12 Darwin/20.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ac702a841b7b2c2747ad1059853c478bded70c6384921d9a43cead7856446b8
|
|
| MD5 |
55c4d375afa98c93215c4423a99a6bd3
|
|
| BLAKE2b-256 |
7d5d8fe317dc03da8173645167f2819cf67adcddd5ba07c602a7a3df6fcee80a
|
File details
Details for the file dddentity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dddentity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.12 Darwin/20.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4320953c4757428fbb4b9e7c4b030eadf67b2d252790755610bfd10a13e9e867
|
|
| MD5 |
9258e88d976a58b3a8fdb59f984414ec
|
|
| BLAKE2b-256 |
8104516782a5ff46fac5e3eaf4490b32c8f91204d168d2d2d5b29d759fa5f308
|