EETimes

Embedded Systems October 2000 Vol13_11

Issue link: http://dc.ee.ubm-us.com/i/71842

Contents of this Issue

Navigation

Page 79 of 181

CHAD BREMMON From OOP to Nuts Object-oriented programming techniques have been slow to become popular for embedded systems development. Maybe the problem isn't OOP, but C++. Here we see how Ada helps make OOP highly effective. key part of successful o bject-ol-ien ted pro- gramming is knowing when not to use it. The example provided by Thomas iemann in his article "Nuts to OOP!" (August 1999, p. 16) were not proof that obj ect- oriented programming (OOP) is flawed. Rather, they were perfect exam- ples of when not to use objects. For those who may not have read Lhe original piece, let me take you back to an article that suggested the increas- ing use of object-oriented program- ming by embedded develo pers is unwarranted . To support his position, the aULhor described an example C++ program in which a DEVICE class pro- \~ded the interface to an unnamed hardware device wi th two 16-bi t regis- ters. Each of th ese registers was abstracted with a template class, called Regi ster, that allowed various ope ra- tions (=, " , &, I, « , and » ) to be per- form ed upon them. The DEVICE class did nothing but give these two regis- ters names. As Michael Barr wrote in his COUll- terpoin t to the original a rticl e: "Abstractions are only useful when they hide something." Mr. iemann 's example hid nothing o[ the underl y- ing behavior and, in addition, took just as many lines of code to control the "abstracted" device as it would have taken to control the device directly. The real purpose of his DEVICE abstrac- tion should have been to get away [rom reading and writing registers. It's tlle results of manipulating tl1e registers th at should be abstracted . In the process, the raw reads and wTites will be hidden. A proper example For the last eight years, I have worked as an embedded software engineer, 78 OCTOBER 2000 Embedded Systems Programming primarily developing software in Ada. Mr. Niemann says "Nuts to OOP!" but 001' isn ' t really his problem. What he o ught to say is "Nuts to C++!" Ignoring tlle weaknesses and overcomplications of his example for a moment, most of the issues that he describes as flaws of OOP are really problems with the C++ language. Be fore responding to Mr. iemann 's many criticisms ofOOP, I'd like to show you a proper use of obj ects to abstract the functionality of a hard- ware device. We begin with the defini- tion and implementa tion of a Regi ster class in Ada95, which are shown together in Listing l. To create and u e a register within your application code, you need only write: My_Register : Register.Object; Register_Create (My_Register, SomeAddress);--set the register

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11