목록C++/Design Pattern (2)
I'm FanJae.
1. Strategy Pattern의 정의다양한 알고리즘이 존재 하면 이들 각각을 하나의 "클래스로 캡슐화하여 알고리즘의 대체가 가능"하도록 한다. Strategy 패턴을 이용하면 클라이언트와 독립적인 다양한 알고리즘으로 변형할 수 있다. 알고리즘을 바꾸더라도 클라이언트는 아무런 변경을 할 필요가 없다. 1-1. 예제를 통한 Strategy Pattern의 필요성 이해#include #include #include class Edit{ std::string data;public: std::string get_text() { std::cin >> data; return data; }};int main(){ Edit edit; while (1) {..
1. Template Method Pattern의 정의 오퍼레이션에는 알고리즘의 처리 과정만을 정의하고 각 단계에서 수행할 구체적인 처리는 서브클래스에서 정의한다. Template Method 패턴은 "알고리즘 처리과정은 변경하지 않고 알고리즘 각 단계의 처리를 서브클래스에서 재정의" 할 수 있게 한다. 1-1. 예제를 통한 Template Method Pattern의 필요성 이해 (코드의 중복)#include #include "Painter.h"class Shape{public: virtual ~Shape() {} virtual void draw() = 0;};class Rect : public Shape{public: void draw() override { std::cout..