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/introduction-to-object-oriented-programming-concep http://www.tutorialspoint.com/cplusplus/cpp_object_oriented.htm http://oopsconcepts.blogspot.ca.
ops -> vtable
t_ops -> half class level vtable
caps -> DI - callback (construct)
cbs -> DI - client/request callback (argument)
객체 지향 프로그래밍의 확실한 원칙
Framework-Lib 클라이언트와 협력 :
모든 건설적인 의견을 환영합니다. 자유롭게 포크하고 기존을 확장하거나 자신의 예제를 추가하고 변경 사항으로 풀 요청을 보내십시오!
MIT 라이센스 (MIT)
저작권 (C) 2014 Wilson Huawen Yu
이에 따라이 소프트웨어 및 관련 문서 파일 ( "소프트웨어")의 사본을 얻는 사람에게는 허가가 부여됩니다. 소프트웨어의 사용, 복사, 수정, 합병, 배포, 배포, 숭고 및/또는 소프트웨어의 사본을 판매 할 권한을 포함하여 제한없이 소프트웨어를 처리 할 수 있도록 소프트웨어를 제공 할 권한이 없습니다.
위의 저작권 통지 및이 권한 통지는 소프트웨어의 모든 사본 또는 실질적인 부분에 포함되어야합니다.
이 소프트웨어는 상업성, 특정 목적에 대한 적합성 및 비 침해에 대한 보증을 포함하여 명시 적 또는 묵시적 보증없이 "그대로"제공됩니다. 어떠한 경우에도 저자 또는 저작권 보유자는 계약, 불법 행위 또는 기타, 소프트웨어 또는 소프트웨어의 사용 또는 기타 거래에서 발생하는 계약, 불법 행위 또는 기타의 행동에 관계없이 청구, 손해 또는 기타 책임에 대해 책임을지지 않습니다.
Pynsource- 파이썬 디자인 패턴을위한 UML 도구가 간단하게 설명되었습니다.
.NET 디자인 패턴
소프트웨어 디자인 패턴
컴퓨터 과학 설계 패턴