Mixins and traits are units of reusable behavior that you compose into a class without a full is-a inheritance relationship. They let unrelated classes share functionality — like multiple inheritance, but focused on behavior rather than building deep type hierarchies.
A mixin in Python
:
():
json
json.dumps(.__dict__)
:
():
time
.updated_at = time.time()
(JsonSerializableMixin, TimestampMixin):
(): .name = name
u = User()
u.touch()
(u.to_json())
