They were originally built for smalltalk, but apparently there is now a python library. I gave it a try, it's actually pretty nice.
Basically, traits provide reusable components of behavior that are not tied to classes. It's pretty sweet. It lets you do things like delegate data members/methods to other objects.
For instance:
class employee(HasTraits):
employer=Trait(company)
class manager(employee):
hire=Delegate('employer','hire')
This code causes an employee to have an employer data member, which MUST be a company object. So far, just static typing (checked at runtime).
The manager subclass of an employee has a "hire" method. But a manager doesn't hire employees himself; instead, he hires employees on behalf of his employer. So boss.hire(emp) is delegated to the boss's employer, and is equivalent to boss.employer.hire(emp).
It has lots of other cute features like this as well. Take a look.
Here is an academic paper describing them:
http://www.iam.unibe.ch/~scg/Archive/Papers/Scha03aTraits.pd...
They were originally built for smalltalk, but apparently there is now a python library. I gave it a try, it's actually pretty nice.
Basically, traits provide reusable components of behavior that are not tied to classes. It's pretty sweet. It lets you do things like delegate data members/methods to other objects.
For instance:
This code causes an employee to have an employer data member, which MUST be a company object. So far, just static typing (checked at runtime).The manager subclass of an employee has a "hire" method. But a manager doesn't hire employees himself; instead, he hires employees on behalf of his employer. So boss.hire(emp) is delegated to the boss's employer, and is equivalent to boss.employer.hire(emp).
It has lots of other cute features like this as well. Take a look.