Explanation of object-oriented concepts in C Language

Source: Internet
Author: User

OO thought has long been in the Unix world: UNIX abstracts devices into files, so that you can use the same method (open, read, write, close ,...) access different devices and files-despite the large differences between devices. From OO's point of view, these "devices" all implement "File Operation interfaces". We can imagine that there is a base class called "file", which defines "File Operation interfaces ", the "device" object inherits the "file" object ..... From the implementation perspective, in the kernel, the device driver provides its own read and write implementations, and uses them to fill in the function pointers in the file operation struct .... this is the same as binding the virtual function in C during runtime. (The C virtual function is actually statically bound at runtime, while the file operation interface can be dynamically bound at runtime :-)

The Linux kernel embodies the idea of OO everywhere. The Device Driver Modal of the 2.6 kernel is a set of hierarchical and intricate mechanisms, which embodies many OO design concepts. Although the device driver developer may not be aware of it, all the device driver objects hide an object called KObject. The kernel associates these KObjects with each other and constructs the/sys file system through the relationship between KObject. /Sys is the ing graph of various device objects in the kernel. If you expand/sys, we can clearly see the relationship between various objects.

Practice has proved that C can also be well used in OO programming and can be used to construct complex systems. In addition, C does not seem lame when expressing OO ideas, but can be very simple, naturally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.