forked from huihut/interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.h
More file actions
34 lines (29 loc) · 710 Bytes
/
adapter.h
File metadata and controls
34 lines (29 loc) · 710 Bytes
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
32
33
34
//
// Created by xiemenghui on 2018/7/20.
//
#ifndef DESIGNPATTERN_ADAPTER_H
#define DESIGNPATTERN_ADAPTER_H
#include "target.h"
#include "adaptee.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p){delete(p); (p)=NULL;} }
#endif
// Power Adapter
class PowerAdapter : public IRussiaSocket
{
public:
PowerAdapter() : m_pCharger(new OwnCharger()){}
~PowerAdapter()
{
SAFE_DELETE(m_pCharger);
}
void Charge()
{
// Use the built-in charger (two-pin flat) to charge
m_pCharger->ChargeWithFeetFlat();
}
private:
// Hold the interface object that needs to be adapted (the built-in charger)
OwnCharger* m_pCharger;
};
#endif //DESIGNPATTERN_ADAPTER_H