Mixin과 trait는 완전한 is-a inheritance 관계 없이 class에 조합하는 재사용 가능한 동작 단위입니다. 이들은 관련 없는 class들이 기능을 공유하게 합니다 — 다중 상속과 비슷하지만, 깊은 타입 계층을 만드는 것이 아니라 동작에 초점을 둡니다.
Python에서의 mixin
python
:
():
json
json.dumps(.__dict__)
:
():
time
.updated_at = time.time()
(JsonSerializableMixin, TimestampMixin):
(): .name = name
u = User()
u.touch()
(u.to_json())
