반응형
mixin
> adding a pile of stuff to a class.
> A mixin is a class such that some method of the class uses a method which is not defined in the class.
A mixin is a special kind of multiple inheritance.
mixins only exist in multiple-inheritance languages. You can't do a mixin in Java or C#.
The difference between a mixin and standard multiple inheritance is just a matter of semantics;
문법적으로는 그냥 다중 상속이고, interface 비슷한 개념인데, interface는 메소드를 다 구현해줘야 하지만,
이건 다 구현되어 있는 유틸리티 느낌
The point of a mixin is to create a type that can be "mixed in" to any other type via inheritance without affecting the inheriting type while still offering some beneficial functionality for that type.
그러니까, 정식으로 상속 받는 부모 클래스 느낌은 아니고, 옆에 꼽사리로 붙어서 효용성을 제공하는 느낌
There are two main situations where mixins are used:
You want to provide a lot of optional features for a class.
You want to use one particular feature in a lot of different classes.
보통 XmlSerializable처럼 able로 끝나는 이름으로 붙이기도 하나봄
http://brownbears.tistory.com/149 여기보면 나와있는데..
믹스인이란 클래스에서 제공해야하는 추가적인 메서드만 정의하는 작은 클래스를 의미한다.
믹스인 클래스는 자체의 인스턴스 속성(attribute)를 정의하지 않으며 __init__생성자를 호출하도록 요구하지 않습니다.
멤버변수가 없고 생성자 이슈를 제거한게 포인트라고 할 수 있겠네
반응형
'Programming' 카테고리의 다른 글
| Python decorator setUp, tearDown 패턴 정리 (0) | 2026.05.17 |
|---|---|
| Python decorator와 pytest 사용 패턴 정리 (0) | 2026.05.17 |
| Matrix Completion과 추천 시스템 정리 (0) | 2026.05.17 |
| Pandas tutorial: DataFrame 기본 사용법 정리 (0) | 2026.05.17 |
| Python decorator class와 type 개념 정리 (0) | 2026.05.16 |
