oop - Data Abstraction in C -


what understood data abstraction hiding technical details user , showing necessary details. data abstraction oop feature. question is: c support data abstraction?

if so, why data abstraction object oriented programming language feature , not procedural language feature?

if answer question no, structures, enums in c? hide details users.

it's possible object oriented programming in c. remember e.g. first c++ compiler c++ c transpiler, python vm written in c etc. thing sets called oop languages apart other better support these constructs, instance in syntax.

one common way provide abstraction function pointers. @ struct linux kernel source below (from include/linux/virtio.h).

/**  * virtio_driver - operations virtio i/o driver  * @driver: underlying device driver (populate name , owner).  * @id_table: ids serviced driver.  * @feature_table: array of feature numbers supported driver.  * @feature_table_size: number of entries in feature table array.  * @probe: function call when device found.  returns 0 or -errno.  * @remove: function call when device removed.  * @config_changed: optional function call when device configuration  *    changes; may called in interrupt context.  */ struct virtio_driver {         struct device_driver driver;         const struct virtio_device_id *id_table;         const unsigned int *feature_table;         unsigned int feature_table_size;         int (*probe)(struct virtio_device *dev);         void (*scan)(struct virtio_device *dev);         void (*remove)(struct virtio_device *dev);         void (*config_changed)(struct virtio_device *dev); #ifdef config_pm         int (*freeze)(struct virtio_device *dev);         int (*restore)(struct virtio_device *dev); #endif }; 

probe, scan, remove etcetera function pointers i/o driver sets themselves. kernel can call these functions i/o driver without need know device. example of abstraction in c. see this article read more particular example.

another form of data abstraction opaque pointers. opaque data type declared in header file, definition never exposed. code doesn't know definition of type can never access it's value, use pointers it. see opaque data type , opaque pointer on wikipedia.

an example of opaque data type you've encountered file stdio.h. same interface used on operating systems, although actual data file * points different. can file * calling fopen , manipulate range of other function calls, may not see data points to.

to learn more object oriented programming in c recommend free online book object oriented programming in ansi-c. check out this dr dobbs article. related questions: object orientation in c , can write object oriented code in c?.


Comments

Post a Comment

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -