SlideShare une entreprise Scribd logo
1  sur  21
객체지향 정리. Part1
khj667@naver.com
절차지향 vs 객체지향
난 c언어 부터 시작을 했다.
c언어의 장점
1)문제 해결을 위한 프로그래밍 언어로써 최적이다. (키워드가 32개…)
2)컴퓨터와 가깝다 보니 공부하면서 os , 메모리 동작 방식 이해
3)다들 c언어 부터 시작하니까… (자료가 많다)
4)난 리눅스 빠돌이….
절차지향 vs 객체지향
공부하면서 객체지향을 배워야 하나 ??
의문이 들음
1)그 당시 c언어로 충분하다고 생각
2)첫 언어를 공부하다 보면 거기에 빠돌이가 된다. (다른 언어 배척..)
3)객체 지향에 대한 코드 복잡도 (지금도 그렇지만 객체지향 프로그래밍을 잘
못 짜면 절차지향 언어 보다도 못하다)
4)나중에 알고보니 사실 전문가는 절차지향 이든 객체지향이든 뭐든지 잘한다.
절차지향 vs 객체지향
업무가 들어왔다.
외부 업체에서 계산기 API 를 만들어 달라 한다.
기능)
더하기, 빼기, 곱하기, 나누기
ㅋㅋ 별거없네..
절차지향 vs 객체지향
void add(int n1, int n2)
{
printf("add result: %dn", n1+n2);
}
void sub(int n1, int n2)
{
printf("sub result: %dn", n1-n2);
}
void mul(int n1, int n2)
{
printf("mul result: %dn", n1*n2);
}
void div(int n1, int n2)
{
printf("div result: %dn", n1/n2);
}
절차지향 vs 객체지향
void add(int n1, int n2)
{
printf("add result: %dn", n1+n2);
}
void sub(int n1, int n2)
{
printf("sub result: %dn", n1-n2);
}
void mul(int n1, int n2)
{
printf("mul result: %dn", n1*n2);
}
void div(int n1, int n2)
{
printf("div result: %dn", n1/n2);
}
4개의 함수를 제공
객체지향을 왜 쓰는지 목적을 가지고 있으므로
고민한번 해보자
뭘 고쳤으면 하는가..
이 정도면 된거 아닌가?
절차지향 vs 객체지향
void calculator(int func, int n1, int n2)
{
switch(func)
{
case 0:
add(n1, n2);
break;
case 1:
sub(n1, n2);
break;
case 2:
mul(n1, n2);
break;
case 3:
div(n1, n2);
break;
default:
break;
}
절차지향 vs 객체지향
void calculator(int func, int n1, int n2)
{
switch(func)
{
case 0:
add(n1, n2);
break;
case 1:
sub(n1, n2);
break;
case 2:
mul(n1, n2);
break;
case 3:
div(n1, n2);
break;
default:
break;
}
}
이 정도면 계산기 API
일단 함수 하나로 묶긴 했는데 …
이정도면 업체에 보낼 수 있겟군..
문제점??
근데 업체에서 func 인자가 어떻게 사용되는지
알아야 한다.
절차지향 vs 객체지향
typedef struct Calculator
{
void (*add)(int, int);
void (*sub)(int, int);
void (*mul)(int, int);
void (*div)(int, int);
}Cal;
int main(void) {
Cal c;
c.add = add;
c.sub = sub;
c.mul = mul;
c.div = div;
c.add(1,3);
return 0;
}
절차지향 vs 객체지향
typedef struct Calculator
{
void (*add)(int, int);
void (*sub)(int, int);
void (*mul)(int, int);
void (*div)(int, int);
}Cal;
int main(void) {
Cal c;
c.add = add;
c.sub = sub;
c.mul = mul;
c.div = div;
c.add(1,3);
return 0;
}
계산기 구조체를 만든다
구조체 안에는
덧셈, 뺄셈, 곱셈, 나눗셈 기능이 들어가 있다.
구조체를 초기화 (함수 포인터)
확실히 의미가 명확해 졌다.
그럼 업체에 API 전달 해야지.
절차지향 vs 객체지향
다시 정리 해보자
업체에서 그러면 API 를 쓸때
1. 구조체 생성.
2. 구조체 초기화 (함수 포인터 연결)
유지 보수 생각한번 해보자
계산기 기능 추가시 우리는 함수를 구현후 구조체 함수포인터를 만들며 초기화 작업을 해줘야 한다.
C언어의 구현방식 모습이 보인다.
절차지향 언어의 특징은 동작 에 촛점이 맞추어져 있다.
그래서 개발 방식도 Top Down 방식이다. (위로 부터 구현)
개발을 어느 정도 해보니 공통적으로 나타나는 현상이 있다.
기능에 대한 구현은 항시 DATA 를 조작해야 한다
절차지향에서는 구현에 촛점이 맞춰있어 DATA 는 LOAD 개념으로 접근한다.
(물론 쩌는 프로그래머는 C언어로 해도 구현이 쩐다…. )
기능 을 목적으로 하지 말고 객체 단위로 바라보자.
절차지향 vs 객체지향
void Calculator(char op, int num1, int num2)
{
switch(op)
{
case '+':
cout << num1+num2;
break;
case '-':
cout << num1-num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1/num2;
break;
default:
break;
}
}
절차지향 vs 객체지향
void Calculator(char op, int num1, int num2)
{
switch(op)
{
case '+':
cout << num1+num2;
break;
case '-':
cout << num1-num2;
break;
case '*':
cout << num1*num2;
break;
case '/':
cout << num1/num2;
break;
default:
break;
}
}
이 코드 구글에서 검색해서 나온 코드이다.
기능을 중점으로 짜면 절차지향 프로그래밍과
다름이 없다.
객체지향 만능을 이야기 하는 것이 아니다.
모든 언어는 언어가 탄생한 배경에 맞게 써야 한
다.
언어의 철학과 탄생배경을 꼭 이해 하도록 하자.
절차지향 vs 객체지향
class Calculator
{
public:
void add(int n1, int n2);
void sub(int n1, int n2);
void mul(int n1, int n2);
void div(int n1, int n2);
};
int main()
{
Calculator C = new Calculator;
C.add(1, 3);
}
절차지향 vs 객체지향
class Calculator
{
public:
void add(int n1, int n2);
void sub(int n1, int n2);
void mul(int n1, int n2);
void div(int n1, int n2);
};
int main()
{
Calculator C = new Calculator;
C.add(1, 3);
}
계산기라는 객체로 바라보는 것이다.
c언어 구현의 중점은
계산기의 기능을 바라보는 것이다.
사실 계산기로만 보면 별 차이 못느낄수 있지만
개념에 대한 이해를 하면 어렵게 느끼지 않을 것
이다.
절차지향 vs 객체지향
typedef struct _ST_STRBUF
{
int m_nLen; // 스트링 길이
char* m_pStr; // 스트링 데이터 힙메모리 주소
}ST_STRBUF;
// a_nStrLen만큼 a_pstStr 구조체를 초기화한다
int mystr_new(ST_STRBUF* a_pstStr, int a_nStrLen);
// 문자열 a_pStr을 a_pstStr의 문자열에 할당한다
int mystr_assign(ST_STRBUF* a_pstStr, char* a_pStr);
// 문자열a_pStr를 a_pstStr문자열 뒤에 붙인다
int mystr_append(ST_STRBUF* a_ptrStr, char* a_pStr);
// 문자a_chFind를 a_pstStr에서 찾는다
int mystr_find(ST_STRBUF* a_pstStr, char a_chFind);
// a_pstStr를 삭제한다
int mystr_delete(ST_STRBUF* a_pstStr);
절차지향 vs 객체지향
int main()
{
ST_STRBUF stStrBuf = { 0, };
mystr_new(&stStrBuf, 256);
// 초기화를 안한다면 아래호출되는 모든 함수는 오동작 할
것이다.
mystr_assign(&stStrBuf, "abc");
mystr_append(&stStrBuf, "def");
// mystr_assign을 먼저 호출하지 않았다면 오동작 할 것이
다.
// 2번째 파라미터가 문자가 아닐 경우 오동작 할수 있다.
// 문자인지 판단하는 함수가 필요하다
mystr_find(&stStrBuf, 'd');
mystr_delete(&stStrBuf);
return 0;
위 소스에 혹시나 발생할 수 있는 오동작 가능성에 대해
적어 보았다.
실제 개발을 하다 보면 에러 처리를 위해 코드의 덩치가
커지는 경우 가 많다
이런 경우 모든 예외 상황에 맞추어 함수를 하나씩 늘려
가다 보면
어떤 함수를 어떤 경우에 호출해야 하는지를 판단하는 것
조차 어렵다.
사실 아래 코드를 누가 실수를 하겠는가... (초보는 제
외...)
하지만 과연 몇만줄의 코드중 아래의 코드를
작성하다 보면
과연 아래의 빠진 부분이 보일까...
절차지향 vs 객체지향
class CMyString
{
public:
int Assign(char* a_pStr);
int Append(char* a_pStr);
int Find(char a_chFind);
public:
CMyString(int a_nSize);
~CMyString();
private:
int m_nLen;
char* m_pStr;
};
int main()
{
CMyString str(256);
str.Assign("abc");
str.Assign("def");
str.Find('d');
return 0;
}
c언어 코드와 비교해 보면 명확해졌다.
즉 어떤 함수를 호출해야 하는지 헷갈릴 가능성
이 줄어 들었다.
(없다는 뜻이 아니다.)
1) 생성자, 소멸자 활용. (heap 자동화)
2) private 변수 외부 접근불가.
절차지향 vs 객체지향
정리
1)data 와 기능은 분리될수가 없다.
2)절차지향 프로그래밍의 핵심은 기능
3)객체지향의 핵심은 데이터
4)서로 바라보는 관점이 다르다
5)객체지향은 bottom UP 프로그래밍에 적합하다.
6)사실 객체든 절차지향이든 결국엔 외부api 가 되었든 오픈소스이든
누군가에게 보여줄수 있는 코드를 만드는게 목적이며 그렇게 프로그래밍을 해야한
DLC 상태캡슐화
솔이가 콜라를 먹는다.
생각나는 대로 코딩해 보자.
Human Sol;
Sol->Drink(Coke); // ??
현실 세계의 객체와 객체지향 세계의 객체 사이에는 중요한 차이점이 있다.
현실속에서는 솔이는 스스로 음료를 마시는 능동적인 존재지만 콜라는 스스로
아무것도 못하는 수동적인 존재이다.
DLC 상태캡슐화
그러나 객체지향의 세계에서 모든 객체는 자신의 상태를 스스로 관리하는
자율적인 존재이다. 콜라 객체의 양을 줄이는 건 콜라 객체 자신이 되어야 한다.
따라서 솔이는 콜라의 음료의 양을 줄일 수 없다.
할수 있는건 솔이가 콜라에게 자신이 콜라를 먹었다라는 메세지를 전달할 뿐이다.
음료의 양을 줄이는건 전적으로 콜라의 몫이다.
이것이 캡슐화…
이렇게 작성한 나도 지키지 못하는 경우가 많네…..

Contenu connexe

Tendances

[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...Seok-joon Yun
 
[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 studySeok-joon Yun
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...Seok-joon Yun
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...Seok-joon Yun
 
[C++ korea] effective modern c++ study item 2 understanding auto type deduc...
[C++ korea] effective modern c++ study   item 2 understanding auto type deduc...[C++ korea] effective modern c++ study   item 2 understanding auto type deduc...
[C++ korea] effective modern c++ study item 2 understanding auto type deduc...Seok-joon Yun
 
Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리ssuser7c5a40
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준Seok-joon Yun
 
C#을 사용한 빠른 툴 개발
C#을 사용한 빠른 툴 개발C#을 사용한 빠른 툴 개발
C#을 사용한 빠른 툴 개발흥배 최
 
C++ 타입 추론
C++ 타입 추론C++ 타입 추론
C++ 타입 추론Huey Park
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기Jongwook Choi
 
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기Chris Ohk
 
[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종빈 오
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010MinGeun Park
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Seok-joon Yun
 
불어오는 변화의 바람, 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++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식은식 정
 
[C++ korea] effective modern c++ study item 1 understand template type dedu...
[C++ korea] effective modern c++ study   item 1 understand template type dedu...[C++ korea] effective modern c++ study   item 1 understand template type dedu...
[C++ korea] effective modern c++ study item 1 understand template type dedu...Seok-joon Yun
 

Tendances (20)

[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study[C++ korea] effective modern c++ study item 17 19 신촌 study
[C++ korea] effective modern c++ study item 17 19 신촌 study
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
 
[C++ korea] effective modern c++ study item 2 understanding auto type deduc...
[C++ korea] effective modern c++ study   item 2 understanding auto type deduc...[C++ korea] effective modern c++ study   item 2 understanding auto type deduc...
[C++ korea] effective modern c++ study item 2 understanding auto type deduc...
 
Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리Refelction의 개념과 RTTR 라이브러리
Refelction의 개념과 RTTR 라이브러리
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
 
C#을 사용한 빠른 툴 개발
C#을 사용한 빠른 툴 개발C#을 사용한 빠른 툴 개발
C#을 사용한 빠른 툴 개발
 
C++ 타입 추론
C++ 타입 추론C++ 타입 추론
C++ 타입 추론
 
C++11
C++11C++11
C++11
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기
 
C++11
C++11C++11
C++11
 
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
 
[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
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
 
불어오는 변화의 바람, 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++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식[C++ korea] effective modern c++ study item 1정은식
[C++ korea] effective modern c++ study item 1정은식
 
[C++ korea] effective modern c++ study item 1 understand template type dedu...
[C++ korea] effective modern c++ study   item 1 understand template type dedu...[C++ korea] effective modern c++ study   item 1 understand template type dedu...
[C++ korea] effective modern c++ study item 1 understand template type dedu...
 

En vedette

2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J
2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J
2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.JAndrew J. Kim
 
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발Jinuk Kim
 
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git민태 김
 
Creating the Evidence Base for mHealth
Creating the Evidence Base for mHealthCreating the Evidence Base for mHealth
Creating the Evidence Base for mHealthcraig lefebvre
 
Análisis comparativo entre las organizaciones
Análisis comparativo entre las organizacionesAnálisis comparativo entre las organizaciones
Análisis comparativo entre las organizacionesCristian Villarraga
 
سور و آيات فاضلة مكتوبة - Warsh- Soar wa Ayat Fadila
سور و آيات فاضلة مكتوبة  - Warsh- Soar wa Ayat Fadila سور و آيات فاضلة مكتوبة  - Warsh- Soar wa Ayat Fadila
سور و آيات فاضلة مكتوبة - Warsh- Soar wa Ayat Fadila b j
 
savills-prime-office-cost-index-q4-2016
savills-prime-office-cost-index-q4-2016savills-prime-office-cost-index-q4-2016
savills-prime-office-cost-index-q4-2016Marcus Arredondo
 
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365SharePoint Evolution 2013 - BUS611 - New ways of working with Office365
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365Antony Clay
 
Recap for Team members
Recap for Team membersRecap for Team members
Recap for Team membersKSARTNL
 
Update of Social Marketing Organization
Update of Social Marketing OrganizationUpdate of Social Marketing Organization
Update of Social Marketing Organizationcraig lefebvre
 
Instituto universitario politécnico
Instituto universitario politécnicoInstituto universitario politécnico
Instituto universitario politécnicoDaniel Rojas
 

En vedette (13)

2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J
2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J
2011년 KTH H3 컨퍼런스 Track B, 세션4 "Advanced Git" by A.J
 
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발
NDC13: DVCS와 코드리뷰 그리고 자동화를 통한 쾌속 개발
 
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
 
Norsk
NorskNorsk
Norsk
 
Creating the Evidence Base for mHealth
Creating the Evidence Base for mHealthCreating the Evidence Base for mHealth
Creating the Evidence Base for mHealth
 
Memito20033
Memito20033Memito20033
Memito20033
 
Análisis comparativo entre las organizaciones
Análisis comparativo entre las organizacionesAnálisis comparativo entre las organizaciones
Análisis comparativo entre las organizaciones
 
سور و آيات فاضلة مكتوبة - Warsh- Soar wa Ayat Fadila
سور و آيات فاضلة مكتوبة  - Warsh- Soar wa Ayat Fadila سور و آيات فاضلة مكتوبة  - Warsh- Soar wa Ayat Fadila
سور و آيات فاضلة مكتوبة - Warsh- Soar wa Ayat Fadila
 
savills-prime-office-cost-index-q4-2016
savills-prime-office-cost-index-q4-2016savills-prime-office-cost-index-q4-2016
savills-prime-office-cost-index-q4-2016
 
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365SharePoint Evolution 2013 - BUS611 - New ways of working with Office365
SharePoint Evolution 2013 - BUS611 - New ways of working with Office365
 
Recap for Team members
Recap for Team membersRecap for Team members
Recap for Team members
 
Update of Social Marketing Organization
Update of Social Marketing OrganizationUpdate of Social Marketing Organization
Update of Social Marketing Organization
 
Instituto universitario politécnico
Instituto universitario politécnicoInstituto universitario politécnico
Instituto universitario politécnico
 

Similaire à 객체지향 정리. Part1

자료구조 Project6
자료구조 Project6자료구조 Project6
자료구조 Project6KoChungWook
 
2012 Ds B1 01
2012 Ds B1 012012 Ds B1 01
2012 Ds B1 01seonhyung
 
C++ 프로그래밍 2014-2018년 기말시험 기출문제
C++ 프로그래밍 2014-2018년 기말시험 기출문제C++ 프로그래밍 2014-2018년 기말시험 기출문제
C++ 프로그래밍 2014-2018년 기말시험 기출문제Lee Sang-Ho
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010Ryan Park
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10Ryan Park
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 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
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기Sang Heon Lee
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features SummaryChris Ohk
 
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013Esun Kim
 
C언어 세미나 - 함수
C언어 세미나 - 함수C언어 세미나 - 함수
C언어 세미나 - 함수SeungHyun Lee
 
C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부Gwangwhi Mah
 
NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스Sungik Kim
 
학교에서 배우지 않는 C
학교에서 배우지 않는 C학교에서 배우지 않는 C
학교에서 배우지 않는 CHeesuk Kang
 
문과생 대상 파이썬을 활용한 데이터 분석 강의
문과생 대상 파이썬을 활용한 데이터 분석 강의문과생 대상 파이썬을 활용한 데이터 분석 강의
문과생 대상 파이썬을 활용한 데이터 분석 강의Kwangyoun Jung
 
More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinDong Chan Shin
 
온라인 게임 처음부터 끝까지 동적언어로 만들기
온라인 게임 처음부터 끝까지 동적언어로 만들기온라인 게임 처음부터 끝까지 동적언어로 만들기
온라인 게임 처음부터 끝까지 동적언어로 만들기Seungjae Lee
 
가능한 C++ 스타일의 캐스트를 즐겨 쓰자
가능한 C++ 스타일의 캐스트를 즐겨 쓰자가능한 C++ 스타일의 캐스트를 즐겨 쓰자
가능한 C++ 스타일의 캐스트를 즐겨 쓰자민욱 이
 

Similaire à 객체지향 정리. Part1 (20)

HI-ARC PS 101
HI-ARC PS 101HI-ARC PS 101
HI-ARC PS 101
 
자료구조 Project6
자료구조 Project6자료구조 Project6
자료구조 Project6
 
2012 Ds B1 01
2012 Ds B1 012012 Ds B1 01
2012 Ds B1 01
 
C++ 프로그래밍 2014-2018년 기말시험 기출문제
C++ 프로그래밍 2014-2018년 기말시험 기출문제C++ 프로그래밍 2014-2018년 기말시험 기출문제
C++ 프로그래밍 2014-2018년 기말시험 기출문제
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
강의자료 2
강의자료 2강의자료 2
강의자료 2
 
[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기[NDC2016] TERA 서버의 Modern C++ 활용기
[NDC2016] TERA 서버의 Modern C++ 활용기
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
 
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
사례를 통해 살펴보는 프로파일링과 최적화 NDC2013
 
C언어 세미나 - 함수
C언어 세미나 - 함수C언어 세미나 - 함수
C언어 세미나 - 함수
 
C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부
 
NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스
 
학교에서 배우지 않는 C
학교에서 배우지 않는 C학교에서 배우지 않는 C
학교에서 배우지 않는 C
 
문과생 대상 파이썬을 활용한 데이터 분석 강의
문과생 대상 파이썬을 활용한 데이터 분석 강의문과생 대상 파이썬을 활용한 데이터 분석 강의
문과생 대상 파이썬을 활용한 데이터 분석 강의
 
More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshin
 
온라인 게임 처음부터 끝까지 동적언어로 만들기
온라인 게임 처음부터 끝까지 동적언어로 만들기온라인 게임 처음부터 끝까지 동적언어로 만들기
온라인 게임 처음부터 끝까지 동적언어로 만들기
 
가능한 C++ 스타일의 캐스트를 즐겨 쓰자
가능한 C++ 스타일의 캐스트를 즐겨 쓰자가능한 C++ 스타일의 캐스트를 즐겨 쓰자
가능한 C++ 스타일의 캐스트를 즐겨 쓰자
 

객체지향 정리. Part1

  • 2. 절차지향 vs 객체지향 난 c언어 부터 시작을 했다. c언어의 장점 1)문제 해결을 위한 프로그래밍 언어로써 최적이다. (키워드가 32개…) 2)컴퓨터와 가깝다 보니 공부하면서 os , 메모리 동작 방식 이해 3)다들 c언어 부터 시작하니까… (자료가 많다) 4)난 리눅스 빠돌이….
  • 3. 절차지향 vs 객체지향 공부하면서 객체지향을 배워야 하나 ?? 의문이 들음 1)그 당시 c언어로 충분하다고 생각 2)첫 언어를 공부하다 보면 거기에 빠돌이가 된다. (다른 언어 배척..) 3)객체 지향에 대한 코드 복잡도 (지금도 그렇지만 객체지향 프로그래밍을 잘 못 짜면 절차지향 언어 보다도 못하다) 4)나중에 알고보니 사실 전문가는 절차지향 이든 객체지향이든 뭐든지 잘한다.
  • 4. 절차지향 vs 객체지향 업무가 들어왔다. 외부 업체에서 계산기 API 를 만들어 달라 한다. 기능) 더하기, 빼기, 곱하기, 나누기 ㅋㅋ 별거없네..
  • 5. 절차지향 vs 객체지향 void add(int n1, int n2) { printf("add result: %dn", n1+n2); } void sub(int n1, int n2) { printf("sub result: %dn", n1-n2); } void mul(int n1, int n2) { printf("mul result: %dn", n1*n2); } void div(int n1, int n2) { printf("div result: %dn", n1/n2); }
  • 6. 절차지향 vs 객체지향 void add(int n1, int n2) { printf("add result: %dn", n1+n2); } void sub(int n1, int n2) { printf("sub result: %dn", n1-n2); } void mul(int n1, int n2) { printf("mul result: %dn", n1*n2); } void div(int n1, int n2) { printf("div result: %dn", n1/n2); } 4개의 함수를 제공 객체지향을 왜 쓰는지 목적을 가지고 있으므로 고민한번 해보자 뭘 고쳤으면 하는가.. 이 정도면 된거 아닌가?
  • 7. 절차지향 vs 객체지향 void calculator(int func, int n1, int n2) { switch(func) { case 0: add(n1, n2); break; case 1: sub(n1, n2); break; case 2: mul(n1, n2); break; case 3: div(n1, n2); break; default: break; }
  • 8. 절차지향 vs 객체지향 void calculator(int func, int n1, int n2) { switch(func) { case 0: add(n1, n2); break; case 1: sub(n1, n2); break; case 2: mul(n1, n2); break; case 3: div(n1, n2); break; default: break; } } 이 정도면 계산기 API 일단 함수 하나로 묶긴 했는데 … 이정도면 업체에 보낼 수 있겟군.. 문제점?? 근데 업체에서 func 인자가 어떻게 사용되는지 알아야 한다.
  • 9. 절차지향 vs 객체지향 typedef struct Calculator { void (*add)(int, int); void (*sub)(int, int); void (*mul)(int, int); void (*div)(int, int); }Cal; int main(void) { Cal c; c.add = add; c.sub = sub; c.mul = mul; c.div = div; c.add(1,3); return 0; }
  • 10. 절차지향 vs 객체지향 typedef struct Calculator { void (*add)(int, int); void (*sub)(int, int); void (*mul)(int, int); void (*div)(int, int); }Cal; int main(void) { Cal c; c.add = add; c.sub = sub; c.mul = mul; c.div = div; c.add(1,3); return 0; } 계산기 구조체를 만든다 구조체 안에는 덧셈, 뺄셈, 곱셈, 나눗셈 기능이 들어가 있다. 구조체를 초기화 (함수 포인터) 확실히 의미가 명확해 졌다. 그럼 업체에 API 전달 해야지.
  • 11. 절차지향 vs 객체지향 다시 정리 해보자 업체에서 그러면 API 를 쓸때 1. 구조체 생성. 2. 구조체 초기화 (함수 포인터 연결) 유지 보수 생각한번 해보자 계산기 기능 추가시 우리는 함수를 구현후 구조체 함수포인터를 만들며 초기화 작업을 해줘야 한다. C언어의 구현방식 모습이 보인다. 절차지향 언어의 특징은 동작 에 촛점이 맞추어져 있다. 그래서 개발 방식도 Top Down 방식이다. (위로 부터 구현) 개발을 어느 정도 해보니 공통적으로 나타나는 현상이 있다. 기능에 대한 구현은 항시 DATA 를 조작해야 한다 절차지향에서는 구현에 촛점이 맞춰있어 DATA 는 LOAD 개념으로 접근한다. (물론 쩌는 프로그래머는 C언어로 해도 구현이 쩐다…. ) 기능 을 목적으로 하지 말고 객체 단위로 바라보자.
  • 12. 절차지향 vs 객체지향 void Calculator(char op, int num1, int num2) { switch(op) { case '+': cout << num1+num2; break; case '-': cout << num1-num2; break; case '*': cout << num1*num2; break; case '/': cout << num1/num2; break; default: break; } }
  • 13. 절차지향 vs 객체지향 void Calculator(char op, int num1, int num2) { switch(op) { case '+': cout << num1+num2; break; case '-': cout << num1-num2; break; case '*': cout << num1*num2; break; case '/': cout << num1/num2; break; default: break; } } 이 코드 구글에서 검색해서 나온 코드이다. 기능을 중점으로 짜면 절차지향 프로그래밍과 다름이 없다. 객체지향 만능을 이야기 하는 것이 아니다. 모든 언어는 언어가 탄생한 배경에 맞게 써야 한 다. 언어의 철학과 탄생배경을 꼭 이해 하도록 하자.
  • 14. 절차지향 vs 객체지향 class Calculator { public: void add(int n1, int n2); void sub(int n1, int n2); void mul(int n1, int n2); void div(int n1, int n2); }; int main() { Calculator C = new Calculator; C.add(1, 3); }
  • 15. 절차지향 vs 객체지향 class Calculator { public: void add(int n1, int n2); void sub(int n1, int n2); void mul(int n1, int n2); void div(int n1, int n2); }; int main() { Calculator C = new Calculator; C.add(1, 3); } 계산기라는 객체로 바라보는 것이다. c언어 구현의 중점은 계산기의 기능을 바라보는 것이다. 사실 계산기로만 보면 별 차이 못느낄수 있지만 개념에 대한 이해를 하면 어렵게 느끼지 않을 것 이다.
  • 16. 절차지향 vs 객체지향 typedef struct _ST_STRBUF { int m_nLen; // 스트링 길이 char* m_pStr; // 스트링 데이터 힙메모리 주소 }ST_STRBUF; // a_nStrLen만큼 a_pstStr 구조체를 초기화한다 int mystr_new(ST_STRBUF* a_pstStr, int a_nStrLen); // 문자열 a_pStr을 a_pstStr의 문자열에 할당한다 int mystr_assign(ST_STRBUF* a_pstStr, char* a_pStr); // 문자열a_pStr를 a_pstStr문자열 뒤에 붙인다 int mystr_append(ST_STRBUF* a_ptrStr, char* a_pStr); // 문자a_chFind를 a_pstStr에서 찾는다 int mystr_find(ST_STRBUF* a_pstStr, char a_chFind); // a_pstStr를 삭제한다 int mystr_delete(ST_STRBUF* a_pstStr);
  • 17. 절차지향 vs 객체지향 int main() { ST_STRBUF stStrBuf = { 0, }; mystr_new(&stStrBuf, 256); // 초기화를 안한다면 아래호출되는 모든 함수는 오동작 할 것이다. mystr_assign(&stStrBuf, "abc"); mystr_append(&stStrBuf, "def"); // mystr_assign을 먼저 호출하지 않았다면 오동작 할 것이 다. // 2번째 파라미터가 문자가 아닐 경우 오동작 할수 있다. // 문자인지 판단하는 함수가 필요하다 mystr_find(&stStrBuf, 'd'); mystr_delete(&stStrBuf); return 0; 위 소스에 혹시나 발생할 수 있는 오동작 가능성에 대해 적어 보았다. 실제 개발을 하다 보면 에러 처리를 위해 코드의 덩치가 커지는 경우 가 많다 이런 경우 모든 예외 상황에 맞추어 함수를 하나씩 늘려 가다 보면 어떤 함수를 어떤 경우에 호출해야 하는지를 판단하는 것 조차 어렵다. 사실 아래 코드를 누가 실수를 하겠는가... (초보는 제 외...) 하지만 과연 몇만줄의 코드중 아래의 코드를 작성하다 보면 과연 아래의 빠진 부분이 보일까...
  • 18. 절차지향 vs 객체지향 class CMyString { public: int Assign(char* a_pStr); int Append(char* a_pStr); int Find(char a_chFind); public: CMyString(int a_nSize); ~CMyString(); private: int m_nLen; char* m_pStr; }; int main() { CMyString str(256); str.Assign("abc"); str.Assign("def"); str.Find('d'); return 0; } c언어 코드와 비교해 보면 명확해졌다. 즉 어떤 함수를 호출해야 하는지 헷갈릴 가능성 이 줄어 들었다. (없다는 뜻이 아니다.) 1) 생성자, 소멸자 활용. (heap 자동화) 2) private 변수 외부 접근불가.
  • 19. 절차지향 vs 객체지향 정리 1)data 와 기능은 분리될수가 없다. 2)절차지향 프로그래밍의 핵심은 기능 3)객체지향의 핵심은 데이터 4)서로 바라보는 관점이 다르다 5)객체지향은 bottom UP 프로그래밍에 적합하다. 6)사실 객체든 절차지향이든 결국엔 외부api 가 되었든 오픈소스이든 누군가에게 보여줄수 있는 코드를 만드는게 목적이며 그렇게 프로그래밍을 해야한
  • 20. DLC 상태캡슐화 솔이가 콜라를 먹는다. 생각나는 대로 코딩해 보자. Human Sol; Sol->Drink(Coke); // ?? 현실 세계의 객체와 객체지향 세계의 객체 사이에는 중요한 차이점이 있다. 현실속에서는 솔이는 스스로 음료를 마시는 능동적인 존재지만 콜라는 스스로 아무것도 못하는 수동적인 존재이다.
  • 21. DLC 상태캡슐화 그러나 객체지향의 세계에서 모든 객체는 자신의 상태를 스스로 관리하는 자율적인 존재이다. 콜라 객체의 양을 줄이는 건 콜라 객체 자신이 되어야 한다. 따라서 솔이는 콜라의 음료의 양을 줄일 수 없다. 할수 있는건 솔이가 콜라에게 자신이 콜라를 먹었다라는 메세지를 전달할 뿐이다. 음료의 양을 줄이는건 전적으로 콜라의 몫이다. 이것이 캡슐화… 이렇게 작성한 나도 지키지 못하는 경우가 많네…..