Metadata-Version: 2.1
Name: roles
Version: 1.0.0
Summary: Role based software development
Home-page: https://github.com/amolenaar/roles
Keywords: role,DCI,data,context,interaction
Author: Arjan Molenaar
Author-email: gaphor@gmail.com
Maintainer: Arjan Molenaar
Maintainer-email: gaphor@gmail.com
Requires-Python: >=3.7,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Software Development :: Libraries
Project-URL: Documentation, https://github.com/amolenaar/roles
Project-URL: Repository, https://github.com/amolenaar/roles
Description-Content-Type: text/markdown

# Roles

Library for Role based development.

Pythonic implementation of the DCI (Data Context Interaction) pattern
(http://www.artima.com/articles/dci_vision.html).

The big difference with mixins is that this role is applied only to the subject
instance, not to the subject class (alas, a new class is constructed).

Roles can be assigned and revoked. Multiple roles can be applied to an
instance. Revocation can happen in any particular order.

Homepage: http://github.com/amolenaar/roles

Releases: http://pypi.python.org/pypi/roles


## Using Roles

As a basic example, consider a domain class:

```python
>>> class Person:
...     def __init__(self, name):
...         self.name = name
>>> person = Person("John")
```

The instance should participate in a collaboration in which it fulfills a
particular role:

```python
>>> from roles import RoleType
>>> class Carpenter(metaclass=RoleType):
...     def chop(self):
...          return "chop, chop"

```
Assign the role to the person:

```python
>>> Carpenter(person)				# doctest: +ELLIPSIS
<__main__.Person+Carpenter object at 0x...>
>>> person					# doctest: +ELLIPSIS
<__main__.Person+Carpenter object at 0x...>

```

The person is still a Person:

```python
>>> isinstance(person, Person)
True

```
... and can do carpenter things:

```python
>>> person.chop()
'chop, chop'

```

See [`roles.py`](http://github.com/amolenaar/roles/blob/master/roles.py) for more examples.

## Context

Roles make a lot of sense when used in a context. A classic example is the
money transfer example. Here two accounts are used and an amount of money is
transfered from one account to the other. So, one account playes the role of
source account and the other plays the role of target account.

An example can be found in [`example.py`](http://github.com/amolenaar/roles/blob/master/example.py).

