Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- class IPacket //pseudo interface
- {
- public:
- virtual ~IPacket() {}
- virtual std::string getDesc(void) = 0; //metoda jest abstrakcyjna
- };
- class IPacketFactory //pseudo interface
- {
- public:
- virtual ~IPacketFactory() {}
- virtual IPacket* createPacket() = 0;//metoda jest abstrakcyjna
- };
- class walkPacket : public IPacket
- {
- public:
- virtual std::string getDesc(void) { return std::string("I am walkPacket!\n"); }
- };
- class movePacket : public IPacket
- {
- public:
- virtual std::string getDesc(void) { return std::string("I am movePacket!\n"); }
- };
- class incomingPacketFactory : public IPacketFactory
- {
- public:
- virtual IPacket* createPacket()
- {
- IPacket* mo = new walkPacket;
- return mo;
- }
- };
- class outgoingPacketFactory : public IPacketFactory
- {
- public:
- virtual IPacket* createPacket()
- {
- IPacket* mo = new movePacket;
- return mo;
- }
- };
- int main()
- {
- IPacketFactory *incomingPacket = new incomingPacketFactory;
- IPacketFactory *outgoingPacket = new outgoingPacketFactory;
- IPacket *walkPacket = incomingPacket->createPacket();
- IPacket *movePacket = outgoingPacket->createPacket();
- std::cout << walkPacket->getDesc();
- std::cout << movePacket->getDesc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement