QtDesignPatterns/templatepattern/interface.h

53 lines
946 B
C
Raw Permalink Normal View History

2024-02-06 17:21:37 +08:00
#include <iostream>
using namespace std;
class Game
{
public:
Game(){}
virtual ~Game(){}
virtual void initialize() = 0;
virtual void startPlay() = 0;
virtual void endPlay() = 0;
virtual void play() final
{
initialize();
startPlay();
endPlay();
}
};
class Cricket : public Game
{
public:
void initialize()
{
cout << "Cricket Game Initialized Start playing" << endl;
}
void startPlay()
{
cout << "Cricket Game Started Enjoy the game" << endl;
}
void endPlay()
{
cout << "Cricket Game Finished" << endl;
}
};
class Football : public Game
{
public:
void initialize()
{
cout << "Football Game Initialized Start playing" << endl;
}
void startPlay()
{
cout << "Football Game Started Enjoy the game" << endl;
}
void endPlay()
{
cout << "Football Game Finished" << endl;
}
};