SlideShare a Scribd company logo
1 of 23
Download to read offline
API Design for C++
Ch.5 API 개발 방법
아꿈사에서 박민규
Styles
•

Flat C

•

Object Orient

•

Template Based

•

Data Driven

ex) FMOD => Flat C, OO, DD http://www.fmod.org/download
Flat C
•

표준 C Lib(stdio.h, stdlib.h, string.h, etc…), Win32 API,
Linux Kernel API, GNOME GLib, NetScape PR, libtiff,
libpng, libz, libungif, etc…

•

ANSI C 추천

•

char, const, continue, default, do, double else, enum,
extern, float, for, goto, if, int, long, register, short, signed,
sizeof, static, struct, switch, typedef, union, unsigned, void,
volatile, while

•

C로 작성하고 C++ 컴파일러로 돌려보세요, 오류를 더 많이 알려준
다
Flat C Style
struct Stack	
{	
int *mStack;	
int mCurSize;	
};	
!
typedef struct Stack *StackPtr;	
!
void StackPush(StackPtr stack, int val);	
!
int StackPop(StackPtr stack);	
!
bool StackIsEmpty(const StackPtr stack);
Flat C Style 호출할때
StackPtr stack = StackCreate();	
if (stack)	
{	
StackPush(stack, 10);	
StackPush(stack, 3);	
while (!StackIsEmpty(stack))	
{	
StackPop(stack);	
}	
StackDestroy(stack);	
}
Flat C Style 장점
•

통합해야할 기존 시스템이 C로 되어 있을때
•

•

예) 리눅스 커널 API를 사용해야 한다면

이진 호환성을 유지해야 할때
Flat C, C++ 같이 쓰기
•

class 같은 키워드 금지

•

extern “c”로 감싸기
#ifdef __cplusplus	
extern “C” {	
#endif	

!
…	

!
#ifdef _cplusplus	
}	
#endif
OO Style
class Stack	
{	
public:	
void Push(int val);	
int Pop();	
bool IsEmpty() const;	
private:	
int *mStack;	
int mCurSize;	
};
OO Style 호출할때
Stack *stack = new Stack();	
if (stack)	
{	
stack->Push(10);	
stack->Push(3);	
while (!stack->IsEmpty())	
{	
stack->Pop();	
}	
delete stack;	
}
OO Style 장점
•

절차적 코드 대신 연결된 모델

•

조금 더 논리적으로 접근

•

클래스를 이용한 데이터와 메서드의 캡슐화
•

예) namespace, public, protected, private
OO Style 단점
•

상속의 복잡성, 애매모호함

•

오남용

•

이진 호환 유지의 어려움
Template Based Style
#include <vector>	
!
template <typename T>	
class Stack	
{	
public:	
void Push(T val);	
T Pop();	
bool IsEmpty() const;	
!
private:	
std::vector<T> mStack;	
};
Template Based Style 호출할때
typedef Stack<int> IntStack;	
!
IntStack *stack = new IntStack();	
if (stack)	
{	
stack->Push(10);	
stack->Push(3);	
while (!stack->IsEmpty())	
{	
stack->Pop();	
}	
delete stack;	
}
Template Based Style 장점

•

중복제거

•

컴파일 타임의 정적 다형성

•

가상메서드를 피할 수 있어 성능 향상
Template Based Style 단점
•

개발시 클래스 템플릿을 헤더에 정의, 명시적 인스턴스화
로 .cpp로 구현 숨기기

•

컴파일 시간 증가

•

바이너리 증가

•

골치아픈 오류 메세지
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));
Data Driven API Style
class Stack	
{	
public:	
Stack();	
Result Command(const std::string &command, const
ArgList *args);	
};
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*, 상속 등을 이용해
가변 파라미터를 이용 할 수 있다
Data Driven API Style의 실행 데
이터 파일

# Input file for data driven Stack API	
Push value:10	
Push value:3	
Pop	
Pop
Data Driven Style 장점
•

비즈니스 로직을 외부로 분리하기 용이, 재컴파일 없이
비즈니스 로직 수정

•

API 하위 버전 호환성 유리
•

•

필요없는 실행 커맨드는 처리 안하면 그만

테스트 자동화 유리
Data Driven Style 단점
•

런타임 성능

•

헤더 파일로 인터페이스 의미를 전달 하기 어려워 문서화
필수

•

타입체크, 유효성 체크 어려움
Flat C, OO, Template
Based, Data-Driven
끝

More Related Content

What's hot

[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C# 혼합 멀티플랫폼 게임 아키텍처 설계
[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C#  혼합 멀티플랫폼 게임 아키텍처 설계[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C#  혼합 멀티플랫폼 게임 아키텍처 설계
[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C# 혼합 멀티플랫폼 게임 아키텍처 설계Sungkyun Kim
 
[shaderx6]8.2 3d engine tools with c++cli
[shaderx6]8.2 3d engine tools with c++cli[shaderx6]8.2 3d engine tools with c++cli
[shaderx6]8.2 3d engine tools with c++cli종빈 오
 
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...Seok-joon Yun
 
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌Seok-joon Yun
 
Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택JinTaek Seo
 
Effective modern cpp item14
Effective modern cpp item14Effective modern cpp item14
Effective modern cpp item14진화 손
 
Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리ssuser7c5a40
 

What's hot (8)

[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C# 혼합 멀티플랫폼 게임 아키텍처 설계
[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C#  혼합 멀티플랫폼 게임 아키텍처 설계[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C#  혼합 멀티플랫폼 게임 아키텍처 설계
[KGC2014] 두 마리 토끼를 잡기 위한 C++ - C# 혼합 멀티플랫폼 게임 아키텍처 설계
 
[shaderx6]8.2 3d engine tools with c++cli
[shaderx6]8.2 3d engine tools with c++cli[shaderx6]8.2 3d engine tools with c++cli
[shaderx6]8.2 3d engine tools with c++cli
 
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
[C++ korea] Effective Modern C++ study item 19 use shared ptr for shared owne...
 
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
 
Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택
 
Effective modern cpp item14
Effective modern cpp item14Effective modern cpp item14
Effective modern cpp item14
 
Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리
 
C++ api design 품질
C++ api design 품질C++ api design 품질
C++ api design 품질
 

Viewers also liked

Grasphatch - Social Venture Captital
Grasphatch - Social Venture CaptitalGrasphatch - Social Venture Captital
Grasphatch - Social Venture Captitalgrasphatch
 
Federmanager bo convegno impermanenza_27_03_13
Federmanager bo  convegno impermanenza_27_03_13Federmanager bo  convegno impermanenza_27_03_13
Federmanager bo convegno impermanenza_27_03_13Marco Frullanti
 
RSA MONTHLY FRAUD REPORT - September 2014
RSA MONTHLY FRAUD REPORT - September 2014RSA MONTHLY FRAUD REPORT - September 2014
RSA MONTHLY FRAUD REPORT - September 2014EMC
 
Mit2 092 f09_lec16
Mit2 092 f09_lec16Mit2 092 f09_lec16
Mit2 092 f09_lec16Rahman Hakim
 
Contractor to client_sample
Contractor to client_sampleContractor to client_sample
Contractor to client_sampleARSEN ROCK
 
Mit2 092 f09_lec04
Mit2 092 f09_lec04Mit2 092 f09_lec04
Mit2 092 f09_lec04Rahman Hakim
 
TechBook: IMS on z/OS Using EMC Symmetrix Storage Systems
TechBook: IMS on z/OS Using EMC Symmetrix Storage SystemsTechBook: IMS on z/OS Using EMC Symmetrix Storage Systems
TechBook: IMS on z/OS Using EMC Symmetrix Storage SystemsEMC
 
Target audience research
Target audience researchTarget audience research
Target audience researchharryronchetti
 
SBIC Enterprise Information Security Strategic Technologies
SBIC Enterprise Information Security Strategic TechnologiesSBIC Enterprise Information Security Strategic Technologies
SBIC Enterprise Information Security Strategic TechnologiesEMC
 
Location shoot
Location shootLocation shoot
Location shootloousmith
 
What Are Your Servers Doing While You’re Sleeping?
What Are Your Servers Doing While You’re Sleeping?What Are Your Servers Doing While You’re Sleeping?
What Are Your Servers Doing While You’re Sleeping?Tracy McKibben
 
Stalking the Kill Chain
Stalking the Kill ChainStalking the Kill Chain
Stalking the Kill ChainEMC
 

Viewers also liked (20)

Grasphatch - Social Venture Captital
Grasphatch - Social Venture CaptitalGrasphatch - Social Venture Captital
Grasphatch - Social Venture Captital
 
Federmanager bo convegno impermanenza_27_03_13
Federmanager bo  convegno impermanenza_27_03_13Federmanager bo  convegno impermanenza_27_03_13
Federmanager bo convegno impermanenza_27_03_13
 
RSA MONTHLY FRAUD REPORT - September 2014
RSA MONTHLY FRAUD REPORT - September 2014RSA MONTHLY FRAUD REPORT - September 2014
RSA MONTHLY FRAUD REPORT - September 2014
 
Mit2 092 f09_lec16
Mit2 092 f09_lec16Mit2 092 f09_lec16
Mit2 092 f09_lec16
 
Contractor to client_sample
Contractor to client_sampleContractor to client_sample
Contractor to client_sample
 
Mit2 092 f09_lec04
Mit2 092 f09_lec04Mit2 092 f09_lec04
Mit2 092 f09_lec04
 
TechBook: IMS on z/OS Using EMC Symmetrix Storage Systems
TechBook: IMS on z/OS Using EMC Symmetrix Storage SystemsTechBook: IMS on z/OS Using EMC Symmetrix Storage Systems
TechBook: IMS on z/OS Using EMC Symmetrix Storage Systems
 
BPR meets ST
BPR meets STBPR meets ST
BPR meets ST
 
Target audience research
Target audience researchTarget audience research
Target audience research
 
SBIC Enterprise Information Security Strategic Technologies
SBIC Enterprise Information Security Strategic TechnologiesSBIC Enterprise Information Security Strategic Technologies
SBIC Enterprise Information Security Strategic Technologies
 
Location shoot
Location shootLocation shoot
Location shoot
 
Doc1
Doc1Doc1
Doc1
 
2015 day 1
2015 day 12015 day 1
2015 day 1
 
Portfolio
PortfolioPortfolio
Portfolio
 
What Are Your Servers Doing While You’re Sleeping?
What Are Your Servers Doing While You’re Sleeping?What Are Your Servers Doing While You’re Sleeping?
What Are Your Servers Doing While You’re Sleeping?
 
Mi3
Mi3Mi3
Mi3
 
Stalking the Kill Chain
Stalking the Kill ChainStalking the Kill Chain
Stalking the Kill Chain
 
3 law of supply
3   law of supply3   law of supply
3 law of supply
 
3349
33493349
3349
 
2015 day 11
2015 day 112015 day 11
2015 day 11
 

Similar to API.Design.for.CPlusPlus.Ch5

NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기Jaeseung Ha
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부JiHyung Lee
 
C Language For Arduino
C Language For ArduinoC Language For Arduino
C Language For Arduino영욱 김
 
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)Tae Young Lee
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 명신 김
 
C언어 세미나 - 함수
C언어 세미나 - 함수C언어 세미나 - 함수
C언어 세미나 - 함수SeungHyun Lee
 
Effective c++ chapter1 2_dcshin
Effective c++ chapter1 2_dcshinEffective c++ chapter1 2_dcshin
Effective c++ chapter1 2_dcshinDong Chan Shin
 
Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉HyunJoon Park
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기Sang Heon Lee
 
Tech Update - The Future of .NET Framework (김명신 부장)
Tech Update - The Future of .NET Framework (김명신 부장)Tech Update - The Future of .NET Framework (김명신 부장)
Tech Update - The Future of .NET Framework (김명신 부장)Eunbee Song
 
C 언어 스터디 01 - 기초
C 언어 스터디 01 - 기초C 언어 스터디 01 - 기초
C 언어 스터디 01 - 기초Yu Yongwoo
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10흥배 최
 
Ai C#세미나
Ai C#세미나Ai C#세미나
Ai C#세미나Astin Choi
 
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)Sang Don Kim
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)Sang Don Kim
 
C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features SummaryChris Ohk
 
PyQGIS와 PyQt를 이용한 QGIS 기능 확장
PyQGIS와 PyQt를 이용한 QGIS 기능 확장PyQGIS와 PyQt를 이용한 QGIS 기능 확장
PyQGIS와 PyQt를 이용한 QGIS 기능 확장MinPa Lee
 
Boost 라이브리와 C++11
Boost 라이브리와 C++11Boost 라이브리와 C++11
Boost 라이브리와 C++11OnGameServer
 

Similar to API.Design.for.CPlusPlus.Ch5 (20)

NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부
 
C Language For Arduino
C Language For ArduinoC Language For Arduino
C Language For Arduino
 
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
파이썬 데이터과학 1일차 - 초보자를 위한 데이터분석, 데이터시각화 (이태영)
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
 
C언어 세미나 - 함수
C언어 세미나 - 함수C언어 세미나 - 함수
C언어 세미나 - 함수
 
Effective c++ chapter1 2_dcshin
Effective c++ chapter1 2_dcshinEffective c++ chapter1 2_dcshin
Effective c++ chapter1 2_dcshin
 
Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉Modern C++의 타입 추론과 람다, 컨셉
Modern C++의 타입 추론과 람다, 컨셉
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
Tech Update - The Future of .NET Framework (김명신 부장)
Tech Update - The Future of .NET Framework (김명신 부장)Tech Update - The Future of .NET Framework (김명신 부장)
Tech Update - The Future of .NET Framework (김명신 부장)
 
C 언어 스터디 01 - 기초
C 언어 스터디 01 - 기초C 언어 스터디 01 - 기초
C 언어 스터디 01 - 기초
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
 
Ai C#세미나
Ai C#세미나Ai C#세미나
Ai C#세미나
 
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)
[Td 2015]windows, linux, mac 신경 안 쓴다. .net 2015와 더더 좋아지는 c# 살짝 훔쳐보기(김명신)
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
 
C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features Summary
 
파이선 실전공략-1
파이선 실전공략-1파이선 실전공략-1
파이선 실전공략-1
 
PyQGIS와 PyQt를 이용한 QGIS 기능 확장
PyQGIS와 PyQt를 이용한 QGIS 기능 확장PyQGIS와 PyQt를 이용한 QGIS 기능 확장
PyQGIS와 PyQt를 이용한 QGIS 기능 확장
 
Boost 라이브리와 C++11
Boost 라이브리와 C++11Boost 라이브리와 C++11
Boost 라이브리와 C++11
 

More from 박 민규

딥러닝제대로시작히기 Ch5 자기부호화기
딥러닝제대로시작히기 Ch5 자기부호화기딥러닝제대로시작히기 Ch5 자기부호화기
딥러닝제대로시작히기 Ch5 자기부호화기박 민규
 
HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템박 민규
 
HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅박 민규
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증박 민규
 
HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증박 민규
 
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2박 민규
 
실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화박 민규
 
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게박 민규
 
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키박 민규
 
HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시박 민규
 
HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리박 민규
 
Doing data science_ch2
Doing data science_ch2Doing data science_ch2
Doing data science_ch2박 민규
 
Basic stack, queue
Basic stack, queueBasic stack, queue
Basic stack, queue박 민규
 

More from 박 민규 (14)

딥러닝제대로시작히기 Ch5 자기부호화기
딥러닝제대로시작히기 Ch5 자기부호화기딥러닝제대로시작히기 Ch5 자기부호화기
딥러닝제대로시작히기 Ch5 자기부호화기
 
HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템
 
HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 
HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증
 
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
 
실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화
 
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
 
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
 
HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시
 
HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리
 
Doing data science_ch2
Doing data science_ch2Doing data science_ch2
Doing data science_ch2
 
Basic stack, queue
Basic stack, queueBasic stack, queue
Basic stack, queue
 
Pig
PigPig
Pig
 

API.Design.for.CPlusPlus.Ch5

  • 1. API Design for C++ Ch.5 API 개발 방법 아꿈사에서 박민규
  • 2. Styles • Flat C • Object Orient • Template Based • Data Driven ex) FMOD => Flat C, OO, DD http://www.fmod.org/download
  • 3. Flat C • 표준 C Lib(stdio.h, stdlib.h, string.h, etc…), Win32 API, Linux Kernel API, GNOME GLib, NetScape PR, libtiff, libpng, libz, libungif, etc… • ANSI C 추천 • char, const, continue, default, do, double else, enum, extern, float, for, goto, if, int, long, register, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while • C로 작성하고 C++ 컴파일러로 돌려보세요, 오류를 더 많이 알려준 다
  • 4. Flat C Style struct Stack { int *mStack; int mCurSize; }; ! typedef struct Stack *StackPtr; ! void StackPush(StackPtr stack, int val); ! int StackPop(StackPtr stack); ! bool StackIsEmpty(const StackPtr stack);
  • 5. Flat C Style 호출할때 StackPtr stack = StackCreate(); if (stack) { StackPush(stack, 10); StackPush(stack, 3); while (!StackIsEmpty(stack)) { StackPop(stack); } StackDestroy(stack); }
  • 6. Flat C Style 장점 • 통합해야할 기존 시스템이 C로 되어 있을때 • • 예) 리눅스 커널 API를 사용해야 한다면 이진 호환성을 유지해야 할때
  • 7. Flat C, C++ 같이 쓰기 • class 같은 키워드 금지 • extern “c”로 감싸기 #ifdef __cplusplus extern “C” { #endif ! … ! #ifdef _cplusplus } #endif
  • 8. OO Style class Stack { public: void Push(int val); int Pop(); bool IsEmpty() const; private: int *mStack; int mCurSize; };
  • 9. OO Style 호출할때 Stack *stack = new Stack(); if (stack) { stack->Push(10); stack->Push(3); while (!stack->IsEmpty()) { stack->Pop(); } delete stack; }
  • 10. OO Style 장점 • 절차적 코드 대신 연결된 모델 • 조금 더 논리적으로 접근 • 클래스를 이용한 데이터와 메서드의 캡슐화 • 예) namespace, public, protected, private
  • 11. OO Style 단점 • 상속의 복잡성, 애매모호함 • 오남용 • 이진 호환 유지의 어려움
  • 12. Template Based Style #include <vector> ! template <typename T> class Stack { public: void Push(T val); T Pop(); bool IsEmpty() const; ! private: std::vector<T> mStack; };
  • 13. Template Based Style 호출할때 typedef Stack<int> IntStack; ! IntStack *stack = new IntStack(); if (stack) { stack->Push(10); stack->Push(3); while (!stack->IsEmpty()) { stack->Pop(); } delete stack; }
  • 14. Template Based Style 장점 • 중복제거 • 컴파일 타임의 정적 다형성 • 가상메서드를 피할 수 있어 성능 향상
  • 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 단점 • 런타임 성능 • 헤더 파일로 인터페이스 의미를 전달 하기 어려워 문서화 필수 • 타입체크, 유효성 체크 어려움
  • 22. Flat C, OO, Template Based, Data-Driven
  • 23.