일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- Entity
- Java
- Entity Set
- 셀레니움
- X.org
- 리눅스 기초
- selenium
- dbms
- systemd
- literal
- X윈도우
- 자바
- 리눅스 마스터 1급
- Reference Type
- Inheritance
- Mac
- python
- 백준
- OOP
- Polymolphism
- zsh
- preprocessing
- 리눅스
- External Scheme
- BFS
- Physical Scheme
- Operator
- Binary Search
- Class
- Unity
- Today
- Total
목록BackEnd/Design Pattern (3)
Byeol Lo
객체 생성을 캡슐화하고, 클라이언트 코드로부터 객체의 생성 로직을 분리하자 객체 생성을 직접 하지 않고, 객체 생성을 담당하고 관리하는 별도의 팩토리 클래스에게 이 일을 위임시켜서 생성 과정을 캡슐화해버린다. 이렇게 되면 생성 로직을 직접 다루지 않도록 하여, 객체 생성의 코드가 변경이나 확장에 유연하게 만들고, 단위 테스트하기에 유리하다. 단점으로는 복잡성이 증가하고, 코드가 분산되어 있어서 파악하기가 쉽지 않다.// Door interfacepublic interface Door { void open(); void close();} // WoodenDoor classpublic class WoodenDoor implements Door { @Override public void..
하나의 클래스는 오직 하나의 인스턴스만을 생성해야 한다. 장점으로는 하나의 인스턴스를 기반으로 공유를 한다면 생성 비용도 줄며, 메모리를 공유할 수 있지만, 단점으로는 의존성이 높아지고, 테스트를 할 때 잘 설정해주어야 한다(한 인스턴스로만 하기 때문에 묶여 있어서 주의해야 함). 특히 DB를 연결한 후에 ORM 기반의 인스턴스를 하나로 운영하는 것도 singleton을 잘 활용한 예라고 할 수 있다. 이렇게 한다면 다른 모듈들이 instance 생성 이라는 프로세스를 여러번 하지 않아도 미리 연결된 instance가 있고, 생성된 instance가 있기 때문에 굳이 RAM을 더 잡아먹어서 생성할 필요가 없다는 것이다(물론 상황에 따라 다르겠지만). 밑은 그 예시다public class Singleto..
객체 지향을 위한 설계에서 빼놓을 수 없는 설계 방식이다.Single Reponsibility Principle (SRP): 단일 책임 원칙Open/Closed Principle (OCP): 개방 폐쇄의 원칙Liskov Substitution Principle (LSP): 리스코프 치환 원칙Interface Segregation Principle (ISP): 인터페이스 분리 원칙Dependency Inversion Principle (DIP): 의존관계 역전 원칙 SRP 한 클래스는 하나의 책임만 가져야 한다(책임은 클 수도 있고 작을 수도 있지만, 경험적으로 지정해야 한다). 책임의 범위를 결정하는 중요한 기준은 "변경" 임. 파급효과를 불러일으키는 설계는 줄이고 적은 쪽으로 설계를 한다. OCP 소..