Skip to content

Instantly share code, notes, and snippets.

Created March 11, 2015 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/56892ac096ea8bcb896c to your computer and use it in GitHub Desktop.
Save anonymous/56892ac096ea8bcb896c to your computer and use it in GitHub Desktop.
Decorator
// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
using std::cin;
class User {
private:
string name;
string pass;
public:
User *create(string name, string pass){
this->name = name;
this->pass = pass;
cout<<name<<endl;
cout<<pass<<endl;
return this;
}
};
class GoogleAnalytics : public User {
private:
User *user;
public:
GoogleAnalytics(User *user){
this->user = user;
this->create("jackie", "chan");
}
User * create(string username, string password){
cout<<"sending data to GA server\t"<<username<<endl;
return user->create(username, password);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
User user;
User *userWithParams = user.create("maksadbek", "password");
User decoratedUser = GoogleAnalytics(new User);
cout<<decoratedUser.name<<endl;
string input;
cin>>input;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment