Practical Statecharts in C/C++: Quantum Programming for Embedded Systems

Appendix A: "C+" Object-Oriented Programming in C

Overview

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.

Bjarne Stroustrup

Many programmers mistakenly think that object-oriented programming (OOP) is possible only with object-oriented languages like Smalltalk, C++, or Java. However, OOP is not the use of a particular language or tool; it is a way to design programs based on the following fundamental meta-patterns.

  • Abstraction the ability to package data with functions into classes.

  • Inheritance the ability to define new classes based on existing classes in order to reuse and organize code.

  • Polymorphism the ability to substitute objects of matching interfaces for one another at run time.

Although these patterns are traditionally associated with object-oriented languages, you can implement them in almost any programming language, including C [1] and assembly. [2] Indeed, Frederick Brooks [Brooks 95] observes:

any of these disciplines [object-oriented meta-patterns] can be had without taking the whole Smalltalk or C++ package many of them predated object-oriented technology.

In fact, hardly any large software system, regardless of implementation language, fails to use abstraction, inheritance, or polymorphism in some form. Easy-to-identify examples include OSF/Motif (the popular object-oriented graphical user interface) and Java Native Interface, both of which are implemented in C. You don't need to look far to find many more such examples.

OOP in an object-oriented language is straightforward because of native support for the three fundamental meta-patterns. However,...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Programming Languages
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.