转到正文

存档

分类: Design Pattern

This is a C++ project that describe the usage of Strategy Pattern design
The aim is to implement one task which is in the page 25 of <Head First> ( Chinese version ).

creatd by Knight 2010.07.15
www.liaoqiqi.com/blog

Full Codes:

继续阅读

This is a C++ project that describe the usage of  Builder Pattern design and Decorator Pattern design.
The aim is to implement one task which is in the page 614 of <Head First> ( Chinese version ).

File List:

  • Vocation.h :   Implement Decorator Pattern design
  • Vocation.cpp : Implement Decorator Pattern design
  • Builder.h : Implement Builder Pattern design
  • Builder.cpp : Implement Builder Pattern design
  • Test.cpp : a test driver

There are several important tips:
1. Java have memory garbage, but C++ don't have. So you should be careful when you use Decorator Pattern design.
The trick is that you should write destructor for every decorator class. ( ex, VocationHotel, VocationTicket )

creatd by Knight 2010.07.14
www.liaoqiqi.com/blog

UML Chart:

继续阅读

I wrote a single pattern with C++ implementation[1] article the day before yesterday. However, this version has one fatal problem: it has Memory Leak  error! This is because you use "new" to malloc memory explicitly, but you never delete it manually. Although OS will help you free this heap, you program reallly exist memory leak problem.

It's well known that Java has garbage collector, so he never thinks of freeing the memory. But we are C++ programmers, we should free heap memory if we new/malloc them.

Ok, Now I'll introduce my C++ single pattern correct version:
继续阅读

There is a pretty good article about how to construct a singleton design patter project in C++[1]. You can learn several methods for this pattern desgin.

It' s very useful and I strongly recommmend you to use one of them.

Example of a C++ Singleton class:

继续阅读

www.liaoqiqi.com网站PR查询 博客简洁版 博客Google_Site_Map 博客Baidu_Site_Map ?