??? 06/20/07 09:58 Read: times |
#141075 - Agree 100% Responding to: ???'s previous message |
Russ,
I'm not sure that I can think of much to add to your posts. OOD promotes abstraction and data hiding, and once you become a convert, you don't want to give it up. OOD also provide inheritance as the natural route to modular code, with the emphasis being firmly on interfaces. I often see C code that is supposedly modular because common code has been put in a function, which is then called from a bunch of different places. This approach usually leads to poor readability and poor maintainability. If you put your UART stuff all in its own source file (uart.c, anyone), and declare any globals in that file as static, you effectively hide them from the outside world. They become private data members of the "uart" class. Of course you have to write accessor methods, along the lines of UartIsFIFOFull() and such.
In cases where your constraints preclude a function call, since after all, simply checking a global status bit is a lot faster and smaller than the overhead of a function call, you might rethink the approach. However, in many cases, the encapsulation is very convenient. Along these lines, you can implement both private and public member functions. Function declarations for the public methods go in the uart.h file and the function declarations for private methods go at the top of uart.c (and should be declared as static). I use this to provide data and function hiding |
Topic | Author | Date |
Object Oriented Programming in C | 01/01/70 00:00 | |
Make it ugly. :) | 01/01/70 00:00 | |
Ugly and scary!!! | 01/01/70 00:00 | |
Logical approach | 01/01/70 00:00 | |
Wasn\\\'t Natural For Me | 01/01/70 00:00 | |
Nice post Russ. | 01/01/70 00:00 | |
Agree 100% | 01/01/70 00:00 | |
OOP in C | 01/01/70 00:00 | |
more OO in C | 01/01/70 00:00 | |
All good hints, for sure | 01/01/70 00:00 |