-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`Options` is now pythonic. Even after subclassing dict, it retains attribute-style access. This commit also contains: - Remove `ContainerMeta` and replace with `__init_subclass__` in BaseContainer` - Remove `BaseSerializer` functionality and associated files - Object Model Documentation
- Loading branch information
Showing
25 changed files
with
271 additions
and
647 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,101 @@ | ||
# Object Model | ||
|
||
DOCUMENTATION IN PROGRESS | ||
Domain elements in Protean have a common structure and share a few behavioral | ||
traits. | ||
|
||
A domain model in Protean is composed with various types of domain elements, | ||
all of which have a common structure and share a few behavioral traits. This | ||
document outlines generic aspects that apply to every domain element. | ||
## Meta Options | ||
|
||
## `Element` Base class | ||
Protean elements have a `meta_` attribute that holds the configuration options | ||
specified for the element. | ||
|
||
`Element` is a base class inherited by all domain elements. Currently, it does | ||
not have any data structures or behavior associated with it. | ||
Options are passed as parameters to the element decorator: | ||
|
||
## Element Type | ||
```python hl_lines="7" | ||
{! docs_src/guides/composing-a-domain/021.py !} | ||
``` | ||
|
||
<Element>.element_type | ||
```python | ||
In [1]: User.meta_ | ||
Out[1]: | ||
{'model': None, | ||
'stream_category': 'user', | ||
'auto_add_id_field': True, | ||
'fact_events': False, | ||
'abstract': False, | ||
'schema_name': 'user', | ||
'aggregate_cluster': User, | ||
'is_event_sourced': False, | ||
'provider': 'default'} | ||
``` | ||
|
||
## Data Containers | ||
### `abstract` | ||
|
||
Protean provides data container elements, aligned with DDD principles to model | ||
a domain. These containers hold the data that represents the core concepts | ||
of the domain. | ||
`abstract` is a common meta attribute available on all elements. An element | ||
that is marked abstract cannot be instantiated. | ||
|
||
There are three primary data container elements in Protean: | ||
!!!note | ||
Field orders are preserved in container elements. | ||
|
||
- Aggregates: The root element that represents a consistent and cohesive | ||
collection of related entities and value objects. Aggregates manage their | ||
own data consistency and lifecycle. | ||
- Entities: Unique and identifiable objects within your domain that have | ||
a distinct lifecycle and behavior. Entities can exist independently but | ||
are often part of an Aggregate. | ||
- Value Objects: Immutable objects that encapsulate a specific value or | ||
concept. They have no identity and provide a way to group related data | ||
without independent behavior. | ||
## Reflection | ||
|
||
### Reflection | ||
Protean provides reflection methods to explore container elements. Each of the | ||
below methods accept a element or an instance of one. | ||
|
||
### `has_fields` | ||
|
||
Returns `True` if the element encloses fields. | ||
|
||
## Metadata / Configuration Options | ||
### `fields` | ||
|
||
Additional options can be passed to a domain element in two ways: | ||
Return a tuple of fields in the element, both explicitly defined and internally | ||
added. | ||
|
||
- **`Meta` inner class** | ||
Raises `IncorrectUsageError` if called on non-container elements like | ||
Application Services or Command Handlers. | ||
|
||
You can specify options within a nested inner class called `Meta`: | ||
### `declared_fields` | ||
|
||
```python hl_lines="13-14" | ||
{! docs_src/guides/composing-a-domain/020.py !} | ||
``` | ||
Return a tuple of the explicitly declared fields. | ||
|
||
- **Decorator Parameters** | ||
### `data_fields` | ||
|
||
You can also pass options as parameters to the decorator: | ||
Return a tuple describing the data fields in this element. Does not include | ||
metadata. | ||
|
||
```python hl_lines="7" | ||
{! docs_src/guides/composing-a-domain/021.py !} | ||
``` | ||
Raises `IncorrectUsageError` if called on non-container elements like | ||
Application Services or Command Handlers. | ||
|
||
### `has_association_fields` | ||
|
||
### `abstract` | ||
Returns `True` if element contains associations. | ||
|
||
### `association_fields` | ||
|
||
Return a tuple of the association fields. | ||
|
||
Raises `IncorrectUsageError` if called on non-container elements. | ||
|
||
### `id_field` | ||
|
||
Return the identity field of this element, or `None` if there is no identity | ||
field. | ||
|
||
### `has_id_field` | ||
|
||
Returns `True` if the element has an identity field. | ||
|
||
### `attributes` | ||
|
||
Internal. Returns a dictionary of fields that generate a representation of | ||
data for external use. | ||
|
||
Attributes include simple field representations of complex fields like | ||
value objects and associations. | ||
|
||
Raises `IncorrectUsageError` if called on non-container elements | ||
|
||
### `auto_add_id_field` | ||
### `unique_fields` | ||
|
||
Return fields marked as unique. | ||
|
||
Abstract elements: | ||
Most elements can be marked abstract to be subclassed. They cannot be instantiated | ||
, but their field orders are preserved. Ex. Events. | ||
Raises `IncorrectUsageError` if called on non-container elements. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.