Doctoc生成的目录
C中的实用设计模式
这将是
== == == == == == == == == == == == == == == == == == == == == == == == == == ==
private protected public static pure
- - - - - - - - - - - - - - - - - - - + - - - - - - - - + - - - - - - - + - - - - - - - - + - - - - - + - -
constructor + + +
destructor
virtual +
methods
virtual + +
routine + + +
variables
member - + +
== == == == == == == == == == == == == == == == == == == == == == == == =
+ have implemented
- can implemented with the "handle/body" idiom , but ...Make a pattern
--------------
$ cd auto-gen
$ make
$ make runall
$ make clean_all
Auto Generate class
-------------------
$ cd tools
$ python gencode.py --file json/prototype.json > log <<< the generated code in dir ./tools/code/c/prototype
OOP来自Myobj.h:
struct shape_rectangle * rect ;
rect = malloc ( sizeof ( * rect ));
if (! rect ) return -1 ;
shape_rectangle_init ( rect );
shape_draw ( & rect -> shape );
shape_free ( & rect -> shape ); struct shape_ops ;
struct shape {
struct shape_ops * ops ;
struct color * _color ;
};
struct shape_ops {
void ( * _destructor )( struct shape * );
void ( * free )( struct shape * );
void ( * draw )( struct shape * );
struct shape_ops * __super ;
};
void shape_init ( struct shape * ); struct shape_rectangle * rect ;
shape_rectangle_init ( rect );
shape_draw ( & rect -> shape );
shape_free ( & rect -> shape ); struct shape_rectangle {
struct shape shape ;
};
void shape_rectangle_init ( struct shape_rectangle * ); struct shape_rectangle * rect ;
struct shape_circle * circle ;
shape_draw ( & rect -> shape );
shape_draw ( & circle -> shape ); // file: OOC.h
struct Class {
size_t size ;
void * ( * ctor ) ( void * self , va_list * app );
};
void * new ( const void * _class , ...) {
const struct Class * class = _class ; // assign the address of `struct String` class
void * p = calloc ( 1 , class -> size ); // allocate the sizeof(struct String);
assert ( p );
* ( const struct Class * * ) p = class ; // Force the conversion of p and set the argument `class` as the value of this pointer.
if ( class -> ctor ) {
va_list ap ;
va_start ( ap , _class );
p = class -> ctor ( p , & ap ); // Now what is `p` here, a `struct String` or `struct Class`.
// and if it is `struct Class` then how it convert to `struct String` in `String_ctor` function
// given below.
va_end ( ap );
}
return p ;
}
// file: mystring.h
#include "OOC.h"
struct String {
const void * class ; // must be first
char * text ;
};
static void * String_ctor ( void * _self , va_list * app ) {
struct String * self = _self ;
const char * text = va_arg ( * app , const char * );
self -> text = malloc ( strlen ( text ) + 1 );
assert ( self -> text );
strcpy ( self -> text , text );
return self ;
}
// Initialization
static const struct Class _String = {
sizeof ( struct String ),
String_ctor
};
const void * String = & _String ;
// file: main.c
#include "mystring.h"
int main ( void )
{
void * a = new ( String , "some text" );
}存储库包含每个设计模式的文件夹。
OOP:http://www.codeproject.com/articles/22769/22769/introduction-to--object-object-oriented-programming-concem-concep http://www.tutorialspoint.com/cplus.com/cplusplus/cplusplus/cpp_obignt/cppp_object_oriented.htmhtmhtm htm htm httm htm htm oppscon.bloggspotcon.ca/
ops -> vtable
t_ops -> half class level vtable
caps -> DI - callback (construct)
cbs -> DI - client/request callback (argument)
面向对象的编程的坚实原则
框架与客户合作:
欢迎所有建设性评论。请随意叉,扩展现有或添加您自己的示例,并通过更改发送拉动请求!
麻省理工学院许可证(MIT)
版权(C)2014 Wilson Huawen Yu
特此免费获得许可,免费授予任何获得此软件副本和相关文档文件(“软件”)的人,以无限制地处理软件,包括无限制的使用权,复制,复制,修改,合并,发布,分发,分发,分发,分配,sublicense和/或允许软件允许与以下条件相关的软件,以下是以下条件。
上述版权通知和此许可通知应包含在软件的所有副本或大量部分中。
该软件是“原样”提供的,没有任何形式的明示或暗示保证,包括但不限于适销性,特定目的的适用性和非侵权的保证。在任何情况下,作者或版权持有人均不应对任何索赔,损害赔偿或其他责任责任,无论是在合同,侵权的诉讼中还是其他索赔,与软件或使用或其他软件中的使用或其他交易有关。
Pynsource- python设计模式的UML工具简单地解释了
.NET设计模式
软件设计模式
计算机科学设计模式