design patterns

  • Thread starter Jean-pierre Martineau
  • Start date
V

Vladimir S. Oka

Zero said:
First you have to switch to C++,
haven't you?

Not necessarily. It is possible to do OO in C as well. Some of the
early C++ compilers were actully just producing C code for the
underlying C compiler.

This, however, still does not make the OP topical here. The
comp.programming group might be a better place to start.
 
S

srikanth

use #include<graphics.h>
with the help of pre definedfunctions you get required graphics
there will also be examples given in help menu
 
S

srikanth

use #include<graphics.h>
with the help of pre definedfunctions you get required graphics
there will also be examples given in help menu
 
S

srikanth

use #include<graphics.h>
with the help of pre definedfunctions you get required graphics
there will also be examples given in help menu
 
V

Vladimir S. Oka

srikanth said:
use #include<graphics.h>
with the help of pre definedfunctions you get required graphics
there will also be examples given in help menu

LoL
 
J

Jean-pierre Martineau

Jean-pierre Martineau a écrit :
> how apply design patterns to c ?
the question was not very clear, i rewrite:
how implément design pattern in style of object oriented programming in c ?
I think it could be simulate Object oriented by subtitute heritance
style by agregation style.

what you think about that ?
 
I

Ian Collins

Jean-pierre Martineau said:
Jean-pierre Martineau a écrit :
the question was not very clear, i rewrite:
how implément design pattern in style of object oriented programming in c ?
I think it could be simulate Object oriented by subtitute heritance
style by agregation style.

what you think about that ?

Yes, OO in C can be done that way. The simplest way to represent an
object in C is to add appropriate function pointers to a struct.
 
M

Malcolm

Jean-pierre Martineau said:
Jean-pierre Martineau a écrit :
the question was not very clear, i rewrite:
how implément design pattern in style of object oriented programming > in
c ?
I think it could be simulate Object oriented by subtitute heritance style
by agregation style.

what you think about that ?
Really you are using the wrong language.

You can design some really elaborate schemes using C, like a function called
"void *queryinterface(Object *obj, char *name)", which returns a structure
full of function pointers implementing the given interface, given that the
object supports it. So a car might implement the "container", "moveable" and
"light source" interfaces.

However it soon gets very unwieldy. You really want a language that will
hide the internal operations for you behind some intutive syntax.
 
A

adampetersen75

Jean-pierre Martineau said:
how apply design patterns to c ?

Design patterns aren't tied to any particular implementation. Many of
the well-known design patterns (consider for example Visitor and
Factory Method) are however not meaningful in a C context; the problems
they solve simply doesn't exist in C.

That said, it is my belief that C programmers can benefit from the
growing catalogue of patterns and I have written an article series
about patterns in C.

My pattern implementations are not be based on techniques for emulating
object oriented features such as inheritance or C++ virtual functions.
In my experience, these features are better left to a compiler;
manually emulating such techniques are obfuscating at best and a source
of hard to track down bugs at worst. Instead, it is my intent to
present implementations that utilizes the strengths of the abstraction
mechanisms already included in the C language

For more details, you can read the series at
http://www.adampetersen.se/

Regards, Adam
 
G

George

Thanks Adam, i've been looking all over the place for a good article
about patterns in C.
 
I

Imre Palik

Jean-pierre Martineau said:
how apply design patterns to c ?

Wich one? :)

Anyway, here is my favorit (I use this even with C++):

Singleton.

data members = static data
private methods = static functions
public methods = global functions

ImRe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top