All Projects → huawenyu → Design Patterns In C

huawenyu / Design Patterns In C

Licence: mit
Practical design patterns in C

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Design Patterns In C

Java-Programs
Java Practiced Problems including concepts of OOPS, Interface, String , Collection.
Stars: ✭ 51 (-72.13%)
Mutual labels:  patterns, oop
Designpatternslibrary
A comprehensive design patterns library implemented in C#, which covers various design patterns from the most commonly used ones to the lesser-known ones. Get familiar with and learn design patterns through moderately realistic examples.
Stars: ✭ 485 (+165.03%)
Mutual labels:  patterns, oop
Designpatterns
DesignPatterns samples by csharp on dotnetcore 《大话设计模式》 中设计模式总结/C#(.NETCore)代码
Stars: ✭ 73 (-60.11%)
Mutual labels:  patterns, oop
Dot
formalization of the Dependent Object Types (DOT) calculus
Stars: ✭ 132 (-27.87%)
Mutual labels:  oop
React Redux Typescript Guide
The complete guide to static typing in "React & Redux" apps using TypeScript
Stars: ✭ 11,621 (+6250.27%)
Mutual labels:  patterns
Designpatternsincsharp
Samples associated with Pluralsight design patterns in c# courses.
Stars: ✭ 149 (-18.58%)
Mutual labels:  patterns
Patterns
Language agnostic patterns description
Stars: ✭ 182 (-0.55%)
Mutual labels:  patterns
Cohesion
A tool for measuring Python class cohesion.
Stars: ✭ 129 (-29.51%)
Mutual labels:  oop
You Don T Know Oop
Знаете ли вы ооп?
Stars: ✭ 170 (-7.1%)
Mutual labels:  oop
Interviews
A list of fancy questions I've been asked during the interviews I had. Some of them I ask when interviewing people.
Stars: ✭ 140 (-23.5%)
Mutual labels:  oop
Sprite Wxapp
spritejs 小程序版
Stars: ✭ 138 (-24.59%)
Mutual labels:  oop
React In Patterns
A free book that talks about design patterns/techniques used while developing with React.
Stars: ✭ 10,948 (+5882.51%)
Mutual labels:  patterns
Expat
Reusable, composable patterns across Elixir libraries
Stars: ✭ 157 (-14.21%)
Mutual labels:  patterns
Restaurantapp
Android Restaurant Application with QR Code Reader
Stars: ✭ 133 (-27.32%)
Mutual labels:  oop
Software Engineer Interview Questions
A lot of questions and links to prepare yourself for an interview.
Stars: ✭ 176 (-3.83%)
Mutual labels:  oop
Globby
User-friendly glob matching
Stars: ✭ 1,864 (+918.58%)
Mutual labels:  patterns
Ploop
Prototype Lua object-oriented program system, with many modern features like attribute, overload, etc. For Lua 5.1 or above, include luajit
Stars: ✭ 163 (-10.93%)
Mutual labels:  oop
Fastflow
FastFlow pattern-based parallel programming framework (formerly on sourceforge)
Stars: ✭ 137 (-25.14%)
Mutual labels:  patterns
Reactpatterns
Patterns for React Developers
Stars: ✭ 1,682 (+819.13%)
Mutual labels:  patterns
Core Spring Patterns
设计模式 by 波波微课
Stars: ✭ 142 (-22.4%)
Mutual labels:  patterns

Table of Contents generated with DocToc

Design-Patterns-in-C

Practical Design Patterns in C

This will be a repository of

  • Implement the Design Patterns of GoF(Gang of Four) in C.
  • (Version 1) Provide script to auto generate Design Patterns into different code style: C, pyNSource(ascii-UML), ... [C++, Java, C#]
  • (Version 2) Reference from Design Patterns in PHP

C oop implement:


======================================================
                private protected public  static  pure
-------------------+--------+-------+--------+-----+--
constructor        +                +       +
destructor
  virtual                           +
methods
  virtual                           +              +
  routine          +                +       +
variables
  member           -                +       +
=================================================
+ have implemented
- can implemented with the "handle/body" idiom, but ...

Quick Start:

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 basic:

The oop come from myobj.h:

  • each class have it's special v-table, here is the struct ops
  • the derive class should also have it's v-table instance, but same type with it's parent
  • the derive class's v-table instance should initial with merge with it's parent

Object

struct shape_rectangle *rect;

rect = malloc(sizeof(*rect));
if (!rect) return -1;
shape_rectangle_init(rect);
shape_draw(&rect->shape);
shape_free(&rect->shape);

Class

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 *);

Data Abstraction & Encapsulation

struct shape_rectangle *rect;

shape_rectangle_init(rect);
shape_draw(&rect->shape);
shape_free(&rect->shape);

Inheritance

struct shape_rectangle {
	struct shape shape;
};

void shape_rectangle_init(struct shape_rectangle *);

Polymorphism

struct shape_rectangle *rect;
struct shape_circle *circle;

shape_draw(&rect->shape);
shape_draw(&circle->shape);

Design Patterns:

  • Using patterns can keep our code loose coupling, cohesive code, and encapsulation.
  • Then we can write maintainable code with a high degree of Orthogonality.
  1. Creational patterns
  • Factory
    • Static Factory
    • Simple Factory
    • Factory Method
      • GoF
      • two stage
    • Abstract Factory
      • GoF family objects
      • two dimension
      • three dimension
  • Builder
  • Prototype
  • Singleton
  1. Structural patterns
  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Private Class Data
  • Handle Body Idiom
  • Proxy
  • MVC
  1. Behavioral patterns
  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

The repository contains a folder by each design pattern.

Contribute

All constructive comments are welcome. Please feel free to fork and extend existing or add your own examples and send a pull request with your changes!

License

The MIT License (MIT)

Copyright (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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See also & References

PyNSource - UML tool for Python Design Patterns Explained Simply
.NET Design Patterns
Software design pattern
Computer Science Design Patterns

TODOS

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/

  • python uml object support
  • manual about oop's basic principle
  • manual about oop C's implement:
ops -> vtable
caps -> DI (construct)
client -> DI (argument)

  • framework-lib cooperate with client:
    • caps: template drive
      • can be simple interface which implement by client and used by class, is callback-functions
      • can be simple factory which implement by client and used by class to create itself, such as client's memory implements
    • DI: dependence on abstract interface
    • derive (instance embed): inheritance as-A
    • client-ops: AI (argument injection)
    • call-ops: smaller client-ops
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].