สารบัญ ที่สร้างขึ้นด้วย 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
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 สำหรับรูปแบบการออกแบบ Python อธิบายได้ง่ายๆ
รูปแบบการออกแบบ. NET
รูปแบบการออกแบบซอฟต์แวร์
รูปแบบการออกแบบวิทยาศาสตร์คอมพิวเตอร์