2010年1月1日 星期五

design pattern

Factory模式
http://www.cppblog.com/converse/archive/2007/03/18/10269.html
定义一个用于创建对象的接口,让子类决定实例化哪一个类。Factory Method 使一个类的实例化延迟到其子类。

Abstract Factory模式
http://www.cppblog.com/converse/archive/2006/07/21/10282.html
提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。

Singleton的C++实现 及相关问题
http://www.sudu.cn/info/html/edu/20061127/236889.html

monostate pattern is a useful alternative to the singleton pattern.

observer pattern
http://www.cppblog.com/converse/archive/2006/08/05/10858.html
定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新.

adapter pattern
http://www.cppblog.com/converse/archive/2006/07/23/10373.html
将一个类的接口转换成客户希望的另外一个接口。Adapt 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。

Acyclic Visitor pattern

Bridge patterns
http://www.cppblog.com/converse/archive/2006/07/23/10376.html
将抽象部分与它的实现部分分离,使它们都可以独立地变化。

Flyweight pattern
运用共享技术有效地支持大量细粒度的对象。
http://www.cppblog.com/converse/archive/2006/08/03/10824.html

curiously recurring template pattern,
stragegy pattern
http://www.cppblog.com/converse/archive/2006/08/07/10902.html
Template Method Pattern
http://www.yuanma.org/data/2009/0120/article_3485.htm

strategy和template method目的相同,皆对『新需求』的不同演算法提供『扩充』的机制,但手法却不同,strategy采用object的方式,利用delegation改变algorithm,而template method则采用class的继承方式来改变algorithm,由於用到的是class的inheritance,所以在compile-time就已经决定要override的algorithm,run-time就无法再改了,但strategy用的是object手法,所以在run-time还可以透过换object改变algorithm。

装饰模式(Decorator Pattern)
http://www.cppblog.com/converse/archive/2006/07/25/10465.html
动态地给一个对象添加一些额外的职责。就增加功能来说,Decorator 模式相比生成子类更为灵活。

访问者模式(Visitor)是一种分离对象数据结构与行为的方法,通过这种分离,可以为一个已存在的类或类群增加新的操作而无需为它们作任何修改
http://www.cppblog.com/emptysoul/archive/2009/02/21/74152.html

Proxy 代理模式(Proxy)的目标是为其他对象提供一个代理或地方以控制对这个对象的访问。当客户向代理对象第一次提出请求时,代理实例化真实对象,并且将请求传给它,以后所有客户请求都经由代理传给真实对象。代理模式分为4类:1、虚拟代理(Virtual Proxy):直到首次请求时才生成一个真实的耗费代理,它用来存放花费大的真实对象。2、远程代理(Remote Proxy):本地的代理对象控制一个远程对象。3、安全代理(Protection Proxy):代理检查调用真实对象所需要的权限。4、聪明引用(Smart Reference):当调用真实对象时,代理处理另外一些事情。
factory pattern.
http://www.cppblog.com/emptysoul/archive/2009/02/12/73469.html

composite pattern,

c++ tech

in test.dll (比方說梯形法求積分 a,b上下極限. n 為切的塊數)

.h 檔
extern "C" __declspec( dllexport ) float __stdcall trapzd(float (*func)(float), float a, float b, int n);

.cpp 檔
float __stdcall trapzd(float (*func)(float), float a, float b, int n)
{ float x,tnm,sum,del;
static float s;
int it,j;
if (n == 1) { return (s=0.5*(b-a)*((*func)(a)+(*func)(b))); } else { for (it=1,j=1;j for (sum=0.0,j=1;j <=it;j++,x+=del) sum += (*func)(x);
s=0.5*(s+(b-a)*sum/tnm);
return s; } }


Declare Function trapzd Lib "test.dll" Alias "trapzd@16" (ByVal fn As Long, ByVal a As Single , ByVal b As Single , ByVal n As Integer) As Single 'double 的不行

Function vbsquare(ByVal x As signle) As Single 'double 的不行
vbsquare = x * x
End Function

sub test
dim a as single a=trapzd(addressof vbsquare,0,1,5)
end sub

但这样做是有条件的,如果 test.dll 中的 float (*func)(float) 用的是 stdcall 调用约定,你就能成功。否则,就算返回了正确的计算结果程序也会崩溃一下,那时没法解决的。
============================================
install boost for Code::blocks
http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef
boost中文說明
http://www.easycpp.org/book/boost官方手册
========================================================= learn open gl
http://xoax.net/comp/cpp/opengl/index.php
=========================================================
找不到 xxxx.h 時

vc++2008
0.ctrl+shift+N -> 一般 -> 空專案
1.方案總管內 滑鼠右鍵->加入->現有項目-> all files required
2.方案總管內 滑鼠右鍵點->屬性->左方c/c++->其它include目錄 加入 "xxxx.h"
(2.先行編譯標頭檔->建立/使用先行編譯標頭->選 未使用先行編譯標頭檔)
c::b
2.in management, mouse right bottom->properties->project settings->project's build options->search directories->compiler-> add "xxxx.h"


==================================================
ex. constructor in c++
class file {
public:
file();
file(file&);
file(const char*);
}

file(); // file fileA;
file(file&); // file fileA=fileB;
file(const char*); file fileA("hello.cpp");

ex. multi inheritance 在繼承兩class, 但兩class有同一父class時
class box: virtual public rect{...};
class frame:virtual public rect{...};
class framebox:public box, public frame{...};

ex. virtual 動態連結
class Door {
public:
virtual void open(); //不知啥門
};

class CarDoor: public Door {
public:
void open(){...}; //開車門
};

class Person {
public:
void OpenDoor(Door& D) const {D.Open();} // 人開門,程式compile時不知開車門或啥門
};

ex. C is B, B is A
class A {public: virtual void f();};
class B: public A {void f();};
class C: public B {void f();};
void main() {
C c;
A *a= &c;
a->f(); // 用的是C::f();
}