Saturday, February 22, 2014

Program to an INTERFACE, not an implementation

@desc
  : 구현이 아닌 인터페이스에 맞춰서 프로그래밍한다.

  : 바뀌는 부분은 따로 뽑아서 캡슐화시킨다. 
    그렇게 하면 나중에 바뀌지 않는 부분에는 영향을 미치지 않은 채로 
    그 부분만 고치거나 확장할 수 있다.

@example
  : Animal Class, Dog Class

Ex1. Programming to an implementation
Dog d = new Dog();
d.bark();

Ex2. Programming to an interface/supertype
Animal animal = new Dog();
animal.makeSound();

Ex3. Assign a concrete implementation object at runtime
Animal animal = getAnimal();
animal.makeSound();





@reference
  : Head First Design Patterns
    by Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates, 1st Ed.

No comments:

Post a Comment