设计模式例程
This commit is contained in:
49
inc/strategy.hpp
Normal file
49
inc/strategy.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "common.hpp"
|
||||
|
||||
class StrategyPerson
|
||||
{
|
||||
public:
|
||||
StrategyPerson(string name, int age, double weight, double height);
|
||||
void showMyself();
|
||||
|
||||
string m_name;
|
||||
int m_age;
|
||||
double m_weight;
|
||||
double m_height;
|
||||
};
|
||||
|
||||
// <20><><EFBFBD>Եij<D4B5><C4B3><EFBFBD>
|
||||
class ICompare
|
||||
{
|
||||
public:
|
||||
virtual bool comparable(StrategyPerson* person1, StrategyPerson* person2) = 0;
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
||||
class CompareByAge :public ICompare
|
||||
{
|
||||
public:
|
||||
bool comparable(StrategyPerson* person1, StrategyPerson* person2);
|
||||
};
|
||||
|
||||
class CompareByHeight :public ICompare
|
||||
{
|
||||
public:
|
||||
bool comparable(StrategyPerson* person1, StrategyPerson* person2);
|
||||
};
|
||||
|
||||
class CompareByWeight :public ICompare
|
||||
{
|
||||
public:
|
||||
bool comparable(StrategyPerson* person1, StrategyPerson* person2);
|
||||
};
|
||||
|
||||
class SortPerson
|
||||
{
|
||||
public:
|
||||
SortPerson(ICompare* pICompare);
|
||||
void sort(vector<StrategyPerson>& personList);
|
||||
private:
|
||||
ICompare* m_CompareStrategy;
|
||||
};
|
Reference in New Issue
Block a user