mirror of
https://github.com/huihut/interview.git
synced 2026-03-13 10:02:55 +08:00
添加设计模式及例子,包括:单例、抽象工厂、适配器、桥接、观察者模式
This commit is contained in:
44
DesignPattern/BridgePattern/concrete_implementor.h
Normal file
44
DesignPattern/BridgePattern/concrete_implementor.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// Created by xiemenghui on 2018/7/21.
|
||||
//
|
||||
|
||||
#ifndef DESIGNPATTERN_CONCRETE_IMPLEMENTOR_H
|
||||
#define DESIGNPATTERN_CONCRETE_IMPLEMENTOR_H
|
||||
|
||||
#include "implementor.h"
|
||||
#include <iostream>
|
||||
|
||||
// 电灯
|
||||
class Light : public IElectricalEquipment
|
||||
{
|
||||
public:
|
||||
// 开灯
|
||||
virtual void PowerOn() override
|
||||
{
|
||||
std::cout << "Light is on." << std::endl;
|
||||
}
|
||||
// 关灯
|
||||
virtual void PowerOff() override
|
||||
{
|
||||
std::cout << "Light is off." << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
// 风扇
|
||||
class Fan : public IElectricalEquipment
|
||||
{
|
||||
public:
|
||||
// 打开风扇
|
||||
virtual void PowerOn() override
|
||||
{
|
||||
std::cout << "Fan is on." << std::endl;
|
||||
}
|
||||
//关闭风扇
|
||||
virtual void PowerOff() override
|
||||
{
|
||||
std::cout << "Fan is off." << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //DESIGNPATTERN_CONCRETE_IMPLEMENTOR_H
|
||||
Reference in New Issue
Block a user