Design Patterns - Decorator - Example 2
2012-06-07 23:08
218 查看
#include <iostream> #include <string> using namespace std; class AbstractStuff { public: virtual string show() { return "Unknown Stuff"; } protected: string discription; }; class BenzCar : public AbstractStuff { public: BenzCar() { discription = "Benz"; } string show() { return discription; } }; class OtherStuff : public AbstractStuff { public: virtual string show() = 0; protected: AbstractStuff *stuff; }; class Wheel : public OtherStuff { public: Wheel(AbstractStuff *stuff) { this->stuff = stuff; } string show() { return stuff->show() + " + wheel"; } }; int main(int argc, char **argv) { AbstractStuff *car = new BenzCar(); car = new Wheel(car); cout << car->show() << endl; return 0; }
相关文章推荐
- Core Design Patterns(1) Decorator 装饰模式
- Design Patterns Example Code (in C++)
- Design patterns IV : Decorator/Wrapper Pattern
- OOP Design (Head First Design Patterns) 学习笔记--04 The decorator pattern
- 《Head First Design Patterns》笔记三:装饰者模式(Decorator Pattern)
- C# Design Patterns (3) - Decorator
- Design Patterns - Command - Example 1
- Head first design patterns c++实现, decorator
- Design Patterns - Abstract Factory - Example 1
- Decorator(Chapter 16 of Pro Objective-C Design Patterns for iOS)
- 艾伟_转载:C# Design Patterns (3) - Decorator
- Microsoft .NET Pet Shop 3.x: Design Patterns and Architecture of the .NET Pet Shop
- head first design patterns这本书值得一读!
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part II)
- [导入]A Taste of AOP from Solving Problems with OOP and Design Patterns (Part I)
- Design Patterns -- Mediator
- MapReduce Design Patterns(chapter 2 (part 2))(三)
- JAVA设计模式(DESIGN PATTERNS IN JAVA)读书摘要 第1部分接口型模式——第3章 适配器(Adapter)模式
- Use Case:Design patterns and Blueprints(续)
- 单例模式——Head First Design Patterns