This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| #include <stdlib.h> | |
| using namespace std; | |
| class Number | |
| { | |
| public: | |
| // 2. Define a public static accessor func | |
| static Number *instance(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Structural Patterns - Adapter | |
| #include <iostream> | |
| using namespace std; | |
| typedef int Coordinate; | |
| typedef int Dimension; | |
| // Desired interface | |
| class Rectangle | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Structural Patterns - Bridge | |
| #include <iostream> | |
| #include <iomanip> | |
| #include <string.h> | |
| using namespace std; | |
| class TimeImp { | |
| public: | |
| TimeImp(int hr, int min) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bridge pattern -- Structural example | |
| using System; | |
| // "Abstraction" | |
| class Abstraction | |
| { | |
| // Fields | |
| protected Implementor implementor; | |
| // Properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Composite design pattern - multiple container classes | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| class Component | |
| { | |
| public: | |
| virtual void traverse() = 0; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| // 1. "lowest common denom" | |
| class Widget | |
| { | |
| public: | |
| virtual void draw() = 0; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| class Interface | |
| { | |
| public: | |
| virtual ~Interface(){} | |
| virtual void write(string &) = 0; | |
| virtual void read(string &) = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| class MainApp | |
| { | |
| static void Main() | |
| { | |
| // Create ConcreteComponent and two Decorators | |
| ConcreteComponent c = new ConcreteComponent(); | |
| ConcreteDecoratorA d1 = new ConcreteDecoratorA(); | |
| ConcreteDecoratorB d2 = new ConcreteDecoratorB(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class MisDepartment | |
| { | |
| public: | |
| void submitNetworkRequest() | |
| { | |
| _state = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Flyweight.h | |
| #include <string> | |
| #include <map> | |
| #include <vector> | |
| #include <iostream> | |
| using namespace std; | |
| class AbstractFont // Flyweight抽象类 | |
| { | |
| protected: |
OlderNewer