Programming

    [Python] overrides 라이브러리 (리스코브 치환 원칙)

    [Python] overrides 라이브러리 (리스코브 치환 원칙)

    Introduction 파이썬에서 클래스 계층 구조를 확장시키다 보면 부모 클래스의 메서드를 오버라이딩 (overriding) 해야 할 일이 분명히 있을 것이다. 오버라이딩이란 부모 클래스를 상속받는 자식 클래스에서, 부모 클래스에서 이미 정의된 메서드를 새로 정의하는 행위를 뜻한다. 아래의 코드를 참고하자. class FooClass(): def __init__(self): pass def foo_function(self): print("Foo function.") return class FooChildClass(FooClass): def __init__(self): pass # Method overrided. def foo_function(self): super().foo_function() prin..

    [Design patterns] Singleton Pattern (싱글턴 패턴)

    [Design patterns] Singleton Pattern (싱글턴 패턴)

    Introduction Design Patterns: Elements of Reusable Object-Oriented Software (1994) 의 저자인 Erich Gamma 는 책이 출판된 15년 후의 인터뷰에서 이렇게 언급한 적이 있다. Larry: How would you refactor "Design Patterns"? Erich: ... When discussing which patterns to drop, we found that we still love them all. (Not really — I'm in favor of dropping Singleton. Its use is almost always a design smell.) 의역하자면 다음과 같다. Larry: "Design P..