10.5 의존관계 Dependencies
Timer header
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <chrono>
class Timer
{
using clock_t = std::chrono::high_resolution_clock;
using second_t = std::chrono::duration<double, std::ratio<1>>;
std::chrono::time_point<clock_t> start_time = clock_t::now();
public:
void elapsed()
{
std::chrono::time_point<clock_t> end_time = clock_t::now();
std::cout << std::chrono::duration_cast<second_t>(end_time - start_time).count() << "\n";
}
};
worker header
//#include "Timer.h"
class Worker
{
public:
void doSomething();
};
Worker.cpp
#include "Worker.h"
#include "Timer.h" // cpp파일에만 있으면 된다.
void Worker::doSomething()
{
Timer timer;
timer.elapsed();
}
main
#include "Worker.h"
using namespace std;
int main()
{
Worker().doSomething();
return 0;
}
의존 Depends-on
- 다른 클래스에도 속할 수 있는가? Yes
- 멤버의 존재를 클래스가 관리? Yes , 단방향.