Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jason_yao committed Feb 25, 2014
1 parent 3f6defc commit 4f63bc3
Show file tree
Hide file tree
Showing 22 changed files with 2,664 additions and 0 deletions.
118 changes: 118 additions & 0 deletions 大話/cpp/adapter/adapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include <string>
#include <iostream>

class Player {
private:
std::string name;

public:
virtual std::string getName();

virtual void setName(std::string name);

virtual void attrack();

virtual void defence();
};

class Center : public Player {

public:
Center(std::string name);

virtual void jinggong();

virtual void fangshou();
};


class Guard : public Player {

public:
Guard(std::string name);

virtual void attrack();

virtual void defence();
};

class Translator : public Player {
public:
Center* wjzf;

Translator(std::string name);

virtual void attrack();

virtual void defence();
};

class AdapterMain {

///
/// * <param name="args"> </param>
///
static void main(std::string args[]);

};

Translator::Translator(std::string name) {
wjzf = new Center(name);
}

void Translator::attrack() {
wjzf->jinggong();
}

void Translator::defence() {
wjzf->fangshou();
}

Center::Center(std::string name) {
this->setName(name);
}

void Center::jinggong() {
std::cout << this->getName() + std::string(" jinggong") << std::endl;
}

void Center::fangshou() {
std::cout << this->getName() + std::string(" fangshou") << std::endl;
}

std::string Player::getName() {
return name;
}

void Player::setName(std::string name) {
this->name = name;
}

void Player::attrack() {
}

void Player::defence() {
}

Guard::Guard(std::string name) {
this->setName(name);
}

void Guard::attrack() {
std::cout << this->getName() + std::string(" attrack") << std::endl;
}

void Guard::defence() {
std::cout << this->getName() + std::string(" defence") << std::endl;
}

int main() {
Player* guard = new Guard("Alston");
guard->attrack();
guard->defence();
Player* center = new Translator("YM");
center->attrack();
center->defence();
return 0;
}

114 changes: 114 additions & 0 deletions 大話/cpp/brige/brige.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <string>
#include <iostream>

class MobileSoft {
public:
virtual void run() = 0;
};

class Mobile {
private:
MobileSoft* soft;
std::string brand;

public:
Mobile(std::string brand);

virtual MobileSoft* getSoft();

virtual void setSoft(MobileSoft* soft);

virtual std::string getBrand();

virtual void setBrand(std::string brand);

virtual void run() = 0;
};

class MobileMp3 : public MobileSoft {
public:
virtual void run();

};

class MotoMible : public Mobile {
public:
MotoMible(std::string brand);

virtual void run();

};

class MobileGame : public MobileSoft {
public:
virtual void run();

};

class NokiaMobile : public Mobile {
public:
NokiaMobile(std::string brand);

virtual void run();

};

MotoMible::MotoMible(std::string brand)
: Mobile(brand) {
}

void MotoMible::run() {
std::cout << "Moto Mobile: " << std::endl;
this->getSoft()->run();
}

NokiaMobile::NokiaMobile(std::string brand)
: Mobile(brand) {
}

void NokiaMobile::run() {
std::cout << "Nokia Mobile: " << std::endl;
this->getSoft()->run();
}

void MobileGame::run() {
std::cout << "run mobile game!" << std::endl;
}

void MobileMp3::run() {
std::cout << "run mobile mp3!" << std::endl;
}

Mobile::Mobile(std::string brand) {
this->brand = brand;
}

MobileSoft* Mobile::getSoft() {
return soft;
}

void Mobile::setSoft(MobileSoft* soft) {
this->soft = soft;
}

std::string Mobile::getBrand() {
return brand;
}

void Mobile::setBrand(std::string brand) {
this->brand = brand;
}

int main() {
Mobile* nokia = new NokiaMobile("Nokia");
MobileSoft* game = new MobileGame();
nokia->setSoft(game);
nokia->run();
Mobile* moto = new MotoMible("Moto");
MobileSoft* mp3 = new MobileMp3();
moto->setSoft(mp3);
moto->run();
return 0;
}


114 changes: 114 additions & 0 deletions 大話/cpp/builder/builder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <string>
#include <iostream>

class PersonBuilder {

public:
virtual void createHead() = 0;
virtual void createBody() = 0;
virtual void createArm() = 0;
virtual void createLeg() = 0;
};

class PersonDirector {

private:
PersonBuilder* pb;

public:
PersonDirector(PersonBuilder* pb);

virtual void createPerson();
};

class ThinPersonBuilder : public PersonBuilder {

public:
virtual void createArm();

virtual void createBody();

virtual void createHead();

virtual void createLeg();

};

class FatPersonBuilder : public PersonBuilder {

public:
virtual void createArm();

virtual void createBody();

virtual void createHead();

virtual void createLeg();

};


class BuilderMain {

///
/// * <param name="args"> </param>
///
static void main(std::string args[]);

};

void ThinPersonBuilder::createArm() {
std::cout << "Create A Thin Arm!" << std::endl;
}

void ThinPersonBuilder::createBody() {
std::cout << "Create A Thin Body!" << std::endl;
}

void ThinPersonBuilder::createHead() {
std::cout << "Create A Thin Head!" << std::endl;
}

void ThinPersonBuilder::createLeg() {
std::cout << "Create A Thin Leg!" << std::endl;
}


void FatPersonBuilder::createArm() {
std::cout << "Create A Fat Arm!" << std::endl;
}

void FatPersonBuilder::createBody() {
std::cout << "Create A Fat Arm!" << std::endl;
}

void FatPersonBuilder::createHead() {
std::cout << "Create A Fat Arm!" << std::endl;
}

void FatPersonBuilder::createLeg() {
std::cout << "Create A Fat Arm!" << std::endl;
}


PersonDirector::PersonDirector(PersonBuilder* pb) {
this->pb = pb;
}

void PersonDirector::createPerson() {
pb->createHead();
pb->createBody();
pb->createArm();
pb->createLeg();
}

int main() {
PersonBuilder* thin = new ThinPersonBuilder();
PersonBuilder* fat = new FatPersonBuilder();
PersonDirector* pd = new PersonDirector(thin);
pd->createPerson();
pd = new PersonDirector(fat);
pd->createPerson();
return 0;
}

Loading

0 comments on commit 4f63bc3

Please sign in to comment.