设计模式例程
This commit is contained in:
102
inc/combination.hpp
Normal file
102
inc/combination.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
#include "common.hpp"
|
||||
|
||||
class ComputerComponent
|
||||
{
|
||||
public:
|
||||
ComputerComponent(string name) :m_name(name) {}
|
||||
virtual void showInfo(string indent = "") = 0;
|
||||
virtual bool isComposite();
|
||||
virtual void startup(string indent = "");
|
||||
virtual void shutdown(string indent = "");
|
||||
|
||||
protected:
|
||||
string m_name;
|
||||
};
|
||||
|
||||
class CPU :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
CPU(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class MemoryCard :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
MemoryCard(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class HardDisk :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
HardDisk(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class GraphicsCard :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
GraphicsCard(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class Battery :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
Battery(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class Fan :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
Fan(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class Displayer :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
Displayer(string name) :ComputerComponent(name) {}
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class ComputerCompsite :public ComputerComponent
|
||||
{
|
||||
public:
|
||||
ComputerCompsite(string name) :ComputerComponent(name) {};
|
||||
void showInfo(string indent);
|
||||
bool isComposite();
|
||||
|
||||
void addComponent(ComputerComponent* component);
|
||||
void removeComponent(ComputerComponent* component);
|
||||
|
||||
void startup(string indent);
|
||||
void shutdown(string indent);
|
||||
|
||||
private:
|
||||
vector<ComputerComponent*> m_components; // <20><><EFBFBD>ɳɷ<C9B3>
|
||||
};
|
||||
|
||||
class Mainboard :public ComputerCompsite
|
||||
{
|
||||
public:
|
||||
Mainboard(string name) :ComputerCompsite(name) {};
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class ComputerCase :public ComputerCompsite
|
||||
{
|
||||
public:
|
||||
ComputerCase(string name) :ComputerCompsite(name) {};
|
||||
void showInfo(string indent);
|
||||
};
|
||||
|
||||
class Computer :public ComputerCompsite
|
||||
{
|
||||
public:
|
||||
Computer(string name) :ComputerCompsite(name) {};
|
||||
void showInfo(string indent);
|
||||
};
|
Reference in New Issue
Block a user