DRUNKEN KEVIN

OOPrinciples SOLID

2009. 11. 23. 09:10

가상


- 상세 설계나, 디자인 설계 과정에서

SOLID part 1: Single Responsibility Principle

http://giorgiosironi.blogspot.com/2009/09/solid-part-1-single-responsibility.html

"There can be only one reason for a class to change."

- 분할통치(Divide and Rule)라고도 함.

- 실제로 복잡한 부분을 추상화하는 것이 핵심

- 클래스의 행위를 한 문장으로 기술해 보는 것이 이 원칙을 적용하는데 도움이 됨.

- 클래스의 재사용성 향상, 클래스가 간단해져 유지보수성 향상, fine-grained 설계 촉진, 테스트 용이


SOLID part 2: Open/Closed Principle

http://giorgiosironi.blogspot.com/2009/09/solid-part-2-openclosed-principle.html

"Classes and methods should be open for extension but closed for modification."


이 원칙을 따르는 사례

- programming to an interface, not an implementation

- template method pattern

- iterator pattern


주안점

- Every good pattern resemble the OCP

- extending behavior without cluttering a base unit

- OCP를 달성하는데 Encapsulation가 도움됨

- OCP forces decoupled and extendable code


SOLID part 3: Liskov Substitution Principle

http://giorgiosironi.blogspot.com/2009/09/solid-part-3-liskov-substitution.html

"Every function or method which expects an object parameter of class A must be able to accept a subclass of A as well, without knowing it."

- 하위 클래스는 언제나 원래 클래스로 대체될 수 있어야 함

- 상속은 Is-A 관계일 때만


SOLID part 4: Interface Segregation Principle

http://giorgiosironi.blogspot.com/2009/09/solid-part-4-interface-segregation.html

"Classes should not depend on interfaces that they not use."

- small interface

- small interface -> less polluted interface -> simplicity of implementation -> less methods -> less tests and less interaction which can cause bugs

- much more cohesive


SOLID part 5: Dependency Inversion Principle

http://giorgiosironi.blogspot.com/2009/09/solid-part-5-dependency-inversion.html

"High level classes should not depend on low level classes. Both should depend upon abstractions. Details should depend upon abstractions. Abstractions should not depend upon details."

- The purpose of this principle is to enable decoupling of software modules.

- The problem with dependency is the transitivity.

- dependency injection을 이용하여 testability를 높인다.


※ 자료출처 : <딱딱하고 재미없게 살아가기>


'가상' 카테고리의 다른 글

전자정부 프레임워크  (2) 2009.12.23
GPU 프로그래밍의 시작, CUDA  (0) 2009.12.22
GPGPU ; General-Purpose computing on GPU  (0) 2009.12.21
OOPrinciples SOLID  (0) 2009.11.23
웹접근성을 준수하는 [탭] 코딩  (2) 2009.07.24
디버깅 원칙 3가지  (4) 2009.06.10