EETimes

Embedded Systems October 2000 Vol13_11

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

Contents of this Issue

Navigation

Page 81 of 181

LISTING 1 'A Register class in 'Ada95 package Register is type Object is private; function Create ( The_Address return Object; procedure Write ( This The_VaLue procedure Read This The_VaLue private type Object is record The_Location: System. Address; end record; end Regi ster; package body Register is function Create ( The_Address return Object is Thi s : Object; begin This.The_Location := The_Address; return This; end Create; procedure Wri te This The_VaLue in out in Object; Unsignedshort Register : Unsignedshort; for Register'Address use This.The_Location; begin Register := The_VaLue; end Write; procedure Read This The_VaLue in out out Register : Unsignedshort; for Register'Address use This.The_Location; begin The_VaLue .- Register; end Read; end Register; Object; Unsignedshort is is in System.Address ) Myths and facts Finally, I would like to take an oppor- tunity to discuss some of the OOP myths and fac ts presen ted by Mr. Niemann. First, what were call ed mytlls: • Objects are needed to IJI'Otect data. In ord er to truly protect data in C++, you must u e the class mechanism. In Ada, however, the decla ration of a private type allows for the protec- tion of d a ta without a class. Unfo rtunately, in C++ the encapsu- lation mecha nism and tlle inhe ri- tance mecha nism a re one and the same. If you would like to declare data as private, you must put that data inside a class. In Ada 95, tlle encapsula tio n can ta ke place regard less of whe the r or no t you use inhe ri tance. Encapsulation is impleme nted in Ada95 by declar- ing types in the private portion of a package. Inhe ritance is implement- ed using tagged types. These mech- a ni ms may be used individually or together to provide an appropriate solution • Objects are needed to group data and IJTOceduTes. Again , if you a re going to protect data and group it with pro- 80 OCTOBER 2000 El11bedded Systel11s Progral11l11ing in in in out in out out System. Address ) Object; Unsignedshort ) ; Object; Unsignedshort ) , . together and pass characters to the digital display. This would in turn send the appropriate on/ off com- mands to the LEDs on the displ ay. These again could be combined to provide a multi-characte r display, to which you could pass a sU-ing as the argume nt. Hie ra rchy may also include inheritance, which involves adding functionali ty and sta te to a class and basing it on anothe r class. For instance, we have an LED that can be turned o n and o ff. We may want to manage an LED that can change colors. This would involve providing a me thod to change the colo r along with a value in tlle sta te to hold the color o f the light. This colo red light could simply inhe rit the rest of its behavior (on and off) from the Light class

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11