OOP with Python
program to an interface
SOLID
SRP; single responsibility principle (Class)
- 클래스를 분리하여 하나의 클래스는 하나의 fole 만 수행하도록
Open-closed
- interface 를 이용하여 클래스를 확장하더라도 최상위 레벨 개념의 클래스(인터페이스)를 변경하지 않아도 되도록 구현
Liskov
- child class가 parent class의 역할을 수행할 수 없다면 상속을 받아 인스턴스화 하지 않는다.
ex)
cat - animal (O)
cat - dog (X)
ISP; interface segregation prinsiple (Interface)
- 특정 클라이언트를 위한 다수 인터페이스가 범용 인터페이스 한 개 보다 낫다.
DIP; depend upon abstractions, not concretions
- 프로그램은 추상화 된 것에 의존하고, 구체화 된 것에 직접적 연결이 없도록 한다.
ex)
자동차 클래스 - 타이어 인터페이스 (의존)
타이어 인터페이스 - 스노우 타이어, 일반 타이어, 광폭 타이어 (구현)
four gangs
Encapsulation
hiding data; decide how to access or modify the information of class
Abstraction
act of specifying a general interface hiding implementation details;
steering wheel or pedal for the car; it hides how the engine moving via pedal or wheel moving via steering wheel
Polymorphism
doing same thing; in a different way
Interihance
make a parent class having common properties to child inherit those characters
and more...
Law of Demeter
- Don't talk to neighbor's neighbor
function name
think how to call it; why call it; who call it
it's there to be called
to eaiser debugging
- return the result
- making object to divide the role; by using instance and method
- don't let one object knows too much about the system
- make a mini world
monty Python