일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Expo
- GitHub
- 스탠실 버퍼 사용
- react native accessible
- CSS
- c++ using
- react native ios 기기 연결
- react native typescript navigate
- node.js
- 리액트 네이티브 맥
- react-native
- unity stencil buffer
- 싸이월드
- node
- react
- 리액트 네이티브 설치 오류
- javascript
- 스탠실 버퍼 튜토리얼
- c++ 정보은닉
- react native mac
- react native
- react native typescript
- cyworld
- react native typescript navigation
- C++
- 벡터와 리스트의 차이
- 스탠실 버퍼 시작
- html
- stencil buffer
- react native 타입스크립트
Archives
- Today
- Total
혀니의 이거저거 뿌시기
[C++]07-1.상속에 들어가기에 앞서 본문
728x90
#include <iostream>
using namespace std;
class PermanentWorker
{
private:
char name[100];
int salary;
public:
PermanentWorker(char *name, int money)
:salary(money)
{
strcpy(this->name, name);
}
int GetPay() const
{
return salary;
}
void ShowSalaryInfo() const
{
cout << "name: " <<name << endl;
cout << "salary: " <<GetPay() <<endl <<endl;
}
}
class EmployeeHandler
{
private:
PermanentWorker* empList[50];
int empNum;
public:
EmployeeHandler() :empNum(0)
{}
void AddEmployee(PermanentWorker* emp)
{
empList[empNum++] = emp;
}
void ShowAllSalaryInfo() const
{
for(int i = 0; < empNum; i++)
empList[i]->ShowSalaryInfo();
}
void ShowTotalSalary() const
{
int sum = 0;
for(int i = 0; i< empNum; i++)
sum+=empList[i]->GetPay();
cout <<"salary sum: " <<sum << endl;
}
~EmployeeHandler()
{
for(int i = 0;i<empNum;i++)
delete empList[i];
}
}
* PermanentWorker: 데이터적 성격이 강함
*EmployeeHandler: 기능적 성격이 강함
*새로운 직원정보의 등록 - AddEmployee
*모든 직원의 이번 달 급여정보 출력 - ShowAllSalaryInfo
*이번 달 급여의 총액 출력 - ShowTotalSalary
=>이렇게 기능의 처리를 실제로 담당하는 클래스를 가리켜 '컨트롤 클래스' or 핸들러클래스 라고 함.
우리는 이제
'요구사항이 변경에 대응하는 프로그램의 유연성', '기능의 추가에 따른 프로그램의 확장성'을 고려하여 만들어야 함
위의 코드에서 영업직, 임시직을 포함하면 모든 코드를 뜯어고쳐야 함
상속을 제대로 이해한다면 EmployeeHandler를 하나도 고치지 않아도 됨.
728x90
'LANG > C++' 카테고리의 다른 글
[C++]07-3.protected선언과 세 가지 형태의 상속 (0) | 2023.05.14 |
---|---|
[C++]07-2.상속의 문법적인 이해 (0) | 2023.05.14 |
[C++]06-3.C++에서의 static (1) | 2023.05.13 |
[C++]06-2.클래스와 함수에 대한 friend 선언 (0) | 2023.05.13 |
[C++]06-1.const와 관련해서 아직 못다한 이야기 (0) | 2023.05.13 |