Introduction
OBC means Object Based C. It is a way and a library
to program Ansi C 89/90 in an object oriented way.
Since C does not directly support objects and inheritance, object oriented
programming in C is also named object based programming. OBC is open source
and published under the GPL.
But why could anybody want to do object oriented programming in C? Here are my
personal top 5 answers:
- You only have a C compiler.
- You need greater flexibility.
- You prefer strict object encapsulation.
- You are irritated by all the language features of C++ and Java.
- You understand, that inheritance is not the cure but the disease.
The OBC programming philosophy is very simple. There are objects and
methods. Objects can be created, destroyed and you can send messages to
them. If an object does not know how to react on a message, it can forward
it to another object. That's it.
OBC offers the following advantages:
- Polymorphism
- Is very flexible. Any object that is represented by
a pointer can be extended to understand OBC methods.
For example FILE* and also C++ objects.
- Can easily implement design patterns like factory method, proxy,
decorator, delegation.
- Has a unit testing system.
- Needs no language extensions.
- No types, classes, interfaces, generics, templates, annotations,
closures, inheritance, friend methods, protected members, exceptions,
auto boxing, operator overloading, inner classes, anonymous classes,
virtual methods, virtual machines, garbage collection, exceptions
- Compiles with Ansi C, C++ or Objective C compilers.
- Is open source under the GPL.
This tutorial demonstrates how to program object based C. It is
intended to be worked through in sequential order.
Download obcSdk.zip and unpack it.
It contains five directories:
- /obc contains all the header and c files needed for OBC.
- /obclib will in the future contain a library of useful object
based on obc.
- /obcdemo contains the sources for the demo used in this tutorial.
- /bin contains a makefile to build the demo project.
- /obcdoc contains this documentation
If you have make and gcc accessible in your shell go to the bin directory
and type "make demo". Start the demo with "./demo.exe".