50 lines
873 B
C++
50 lines
873 B
C++
#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;
|
|
};
|
|
|
|
// ²ßÂԵijéÏó
|
|
class ICompare
|
|
{
|
|
public:
|
|
virtual bool comparable(StrategyPerson* person1, StrategyPerson* person2) = 0;
|
|
};
|
|
|
|
// ¾ßÌåµÄ²ßÂÔ
|
|
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;
|
|
};
|