Daftar isi yang dihasilkan dengan dokter
Pola desain praktis di c
Ini akan menjadi gudang
== == == == == == == == == == == == == == == == == == == == == == == == == == ==
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 berasal dari 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" );
}Repositori berisi folder dengan setiap pola desain.
OOP: http://www.codeproject.com/articles/22769/introduction-to-object-oriented-programming-concep http://www.tutorialspoint.com/cplusplus/ccppps.object.oriented.htm http:/cplusplus/ccpps.cote.aented.htm http:/ccppppps.coPoT.coPoT.coP.CASCOP.CASCOC.CASCOP.CAPOT.CAPOT.COP.CAPOT.COP.CAPOT.COP.CAPOT.COP.CAPOCE.COPCOC.
ops -> vtable
t_ops -> half class level vtable
caps -> DI - callback (construct)
cbs -> DI - client/request callback (argument)
Prinsip-prinsip yang solid dari pemrograman yang berorientasi objek
kerangka kerja-lib bekerja sama dengan klien:
Semua komentar konstruktif dipersilakan. Silakan fork dan memperluas yang ada atau tambahkan contoh Anda sendiri dan kirim permintaan tarik dengan perubahan Anda!
Lisensi MIT (MIT)
Hak Cipta (C) 2014 Wilson Huawen Yu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Pemberitahuan hak cipta di atas dan pemberitahuan izin ini harus dimasukkan dalam semua salinan atau bagian substansial dari perangkat lunak.
Perangkat lunak ini disediakan "sebagaimana adanya", tanpa jaminan apa pun, tersurat maupun tersirat, termasuk tetapi tidak terbatas pada jaminan dapat diperjualbelikan, kebugaran untuk tujuan tertentu dan nonpringement. Dalam hal apa pun penulis atau pemegang hak cipta tidak akan bertanggung jawab atas klaim, kerusakan atau tanggung jawab lainnya, baik dalam tindakan kontrak, gugatan atau sebaliknya, timbul dari, di luar atau sehubungan dengan perangkat lunak atau penggunaan atau transaksi lain dalam perangkat lunak.
Pynsource - Alat UML untuk pola desain Python dijelaskan sederhana
Pola desain .NET
Pola Desain Perangkat Lunak
Pola Desain Ilmu Komputer