15. Template Based Style 단점
•
개발시 클래스 템플릿을 헤더에 정의, 명시적 인스턴스화
로 .cpp로 구현 숨기기
•
컴파일 시간 증가
•
바이너리 증가
•
골치아픈 오류 메세지
16. Data Driven API Style
// flat c-style
func(obj, a, b, c);
!
// object-orient style
obj.func(a, b, c);
!
// data-driven function with parameters
send(“func”, a, b, c);
!
//data-driven function with a dictionary
send(“func”, dict(arg1 = a, arg2 = b, arg3 = c));
17. Data Driven API Style
class Stack
{
public:
Stack();
Result Command(const std::string &command, const
ArgList *args);
};
18. Data Driven API Style 호출할때
s = new Stack();
if (s)
{
s->Command(“Push”, ArgList().Add(“value”, 10));
s->Command(“Push”, ArgList().Add(“value”, 3));
Stack::Result r = s->Command(“IsEmpty”);
while (!r.convertToBool())
{
s->Command(“Pop”);
r = s->Command(“IsEmpty”);
}
delete s;
}
Tip: QT의 QVariant, Boost의 any, Union, void*, 상속 등을 이용해
가변 파라미터를 이용 할 수 있다
19. Data Driven API Style의 실행 데
이터 파일
# Input file for data driven Stack API
Push value:10
Push value:3
Pop
Pop
20. Data Driven Style 장점
•
비즈니스 로직을 외부로 분리하기 용이, 재컴파일 없이
비즈니스 로직 수정
•
API 하위 버전 호환성 유리
•
•
필요없는 실행 커맨드는 처리 안하면 그만
테스트 자동화 유리
21. Data Driven Style 단점
•
런타임 성능
•
헤더 파일로 인터페이스 의미를 전달 하기 어려워 문서화
필수
•
타입체크, 유효성 체크 어려움