Abstract
In this project you will learn:
✅ How to encapsulate behavior and state in C (simulating classes and objects);
✅ Using function pointers to organize sets of interface functions;
✅ Implementing polymorphic behavior through struct nesting and method tables;
✅ How to organize all of this into a clear .h and .c file structure;
✅ A modular development approach suited to embedded projects.
This article involves a lot of advanced C topics, such as function pointers, struct pointers, double pointers, frequent referencing and dereferencing of pointers, typedef, static, inline, and C project structure. Please make sure you will not be overwhelmed by the above. If you have no such worries, enjoy~
Project address: https://github.com/swfeiyu/coop
1. Origin
At first I did not know about this technique. One day, while browsing Bilibili, I came across a video by a creator called "一点五编程" (One-Point-Five Programming). He proposed a programming idea and named it "one-point-five programming". In it:
(1) "One" refers to the idea of modularity
(2) "Point-Five" refers to the (*p)->f(p) technique
When I saw it, it looked like an advanced technique, so I started watching his videos, only to find that all the videos explaining the core of this technique were paid (charge-to-watch)!!! Fine, then I had no choice but to read his documentation, and I found his personal blog. Hmm, it seems to cover everything, but something seems to be missing... Oh, it does not teach me how to actually organize the files.
Then I kept browsing the web and found three articles on CSDN that interpret "One-Point-Five Programming". But later, in my own hands-on practice, I still found errors in them.
After reading so many articles and videos, it suddenly hit me: isn't this just the object-oriented programming paradigm? It is just that C is a procedural language and has no ready-made object-oriented components, but in terms of ideas it is entirely that OOP approach!
So I started digging into it myself, and finally I worked it out~
At the end of the article I will include a line-following car project, although the functionality is only faked (smirk). First, let's go over the basic theory and development flow of this technique.
2. Object-Oriented Programming
Let's first talk about what object-oriented programming is:
Object-oriented programming is a programming paradigm that organizes and designs programs by defining classes and objects.
In object-oriented programming, programmers define data structures and behavior by creating classes, instantiate those classes by creating objects, and implement the program's functionality through interaction between objects. This approach makes the program structure clearer and easier to maintain.
Object-oriented programming has several features: encapsulation, inheritance, polymorphism, and abstraction. I won't go into them here; just know that this article will demonstrate them. (Hesitant) After all, they are quite hard to understand and I can't explain them well, so you can read articles by other experts.
Why bring up object-oriented programming? As everyone knows, embedded systems is a discipline that combines software and hardware, which creates a problem: we care a great deal about the hardware implementation,and once the upper-layer functionality works, we don't care about the development structure, later maintenance, and so on. This is vividly reflected in beginners.
Object-oriented programming is committed to making programs more modular. Through inheritance and polymorphism, a large amount of code can be reused, and it can also model objects and relationships in the real world.This gives developers a top-down development approach. At the same time, it isolates the upper-layer implementation from the lower-layer drivers, making it easy to change development platforms.
3. Developing Object-Oriented Programs in C
I divide the whole development of object-oriented programming in C into three stages: declaration, implementation, and use.









