Skip to main content

Role based development

Project description

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://amolenaar.github.com/roles

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

Using Roles

As a basic example, consider a domain class:

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

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

>>> from roles import RoleType
>>> class Carpenter(object):
...     __metaclass__ = RoleType
...     def chop(self):
...          return "chop, chop"

Assign the role to the person:

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

The person is still a Person:

>>> isinstance(person, Person)
True

… and can do carpenter things:

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

See 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 and example2.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roles-0.8.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

roles-0.8-py2.6.egg (14.2 kB view details)

Uploaded Source

File details

Details for the file roles-0.8.tar.gz.

File metadata

  • Download URL: roles-0.8.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for roles-0.8.tar.gz
Algorithm Hash digest
SHA256 f2c36b4f2748f6b7b9e19373a09893e561831bd9f8c554e138a4eb1ab9a0896c
MD5 a31ffd3047bb190b7429c802cbd52e66
BLAKE2b-256 604a8fc0a67037a6ef4ea30a8e869aa91a1f67da223dcbacbac35371428c67ad

See more details on using hashes here.

File details

Details for the file roles-0.8-py2.6.egg.

File metadata

  • Download URL: roles-0.8-py2.6.egg
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for roles-0.8-py2.6.egg
Algorithm Hash digest
SHA256 0aa3fe67f0d2922821dc71f6ddb9d0e09cb92f31b187c1e8c43b9ce0b6258780
MD5 9cad76f567b2b4010a7f2d7620f2ce75
BLAKE2b-256 a41511f4aba05414812f2b7c808e28a1eac0299c2f5e6bdc551ba99f82513e67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page