In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to analyze RT-Thread object-oriented programming ideas, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Preface
To face the process is to encounter a problem and list the solution to the problem step by step, just like playing chess, step by step, and adjust your thinking according to the specific situation. Process-oriented is to abstract logic, that is, to abstract into an object or object.
An object can be summarized as follows:
01
The benefits of object orientation
In programming, if we use object-oriented to design programs, on the one hand, we consider the advantages of structured design programs, on the other hand, we also consider the mapping relationship between the real world and object-oriented space.
The details are as follows:
(1) it is in line with human thinking habits and can naturally represent the entities and problems of the real world.
Our programs often operate specific objects in real life, such as door lock control, the methods of door lock are to open and close the door, the state of the door lock has been closed, has been opened, or is being opened or is being closed, the composition of the door lock has a mechanical structure and handle, the meaning of the door lock is to ensure family safety. With these thoughts, we can abstract the door lock control program into an object.
(2) effective ways of code reuse
When the program is abstracted, many methods can be reused, we can abstract specific things, such as door locks, can be abstracted into motor control, the forward and reverse rotation of the motor is not only suitable for door locks, but also suitable for other things such as handles, so after abstraction, the motor method can be reused by the handle and the lock body at the same time, greatly simplifying the logic.
(3) Encapsulation makes objects relatively independent, which brings convenience to software maintenance.
This understanding is more simple, that is, it reduces the coupling of programming, and when modifying or changing a function, it will not cause confusion in the logic of the program.
(4) Polymorphism enhances the transparency, understanding and maintainability of the operation.
The combination of polymorphism and inheritance enhances the flexibility and reusability of the software. Due to the support of polymorphism, the design of the software is more flexible and stable.
(5) Modularization
In order to obtain software with good maintainability, reusability and compatibility, the system structure of the software should be modular. A good module has the characteristics of high cohesion and low coupling, and the software quality is guaranteed.
02
Object-oriented thought in rt-thread
Anything that exists objectively in the real world can be called an object. Attributes and operations are the two elements of an object. Attributes describe the static characteristics of objects, and operations describe the dynamic characteristics of objects.
We all know that C language is process-oriented and how it is designed to be object-oriented.
Struct object
{
Int field
}
Struct child_object
{
Struct object parent
Int a
Int b
}
To put it simply, it is the nesting of structures.
All types of God in rtthread are rt_object.
A rt_object has the following attributes:
The object has a corresponding name, type, identity, and the next linked list.
For example, ipc, the communication mechanism between messages.
These are all integrated based on the base class of rt_ipc_object.
Therefore, this object-oriented idea is widely used in the programming of rt-thread.
03
Management of objects in rt-thread
We know that objects need to be managed, and it is impossible to form a system if it is only a single object. The management of objects in rt-thread is shown below:
Object containers are operating objects, and we insert these containers into the linked list through specific methods, which are managed by the operating system. There are four types of interfaces:
1. Initialize object
Void rt_object_init (struct rt_object* object, enum rt_object_class_type type, const char* name)
Initializing the object sets the appropriate category and places it in the corresponding object container linked list.
two。 Break away from the object
Void rt_object_detach (rt_object_t object)
Detaching the object is removed from the corresponding object container linked list.
3. Allocation object
Rt_object_t rt_object_allocate (enum rt_object_class type type, const char* name)
For a dynamic object, the corresponding object data block needs to be allocated before use. When the object type is specified, the corresponding block size is also obtained from the object table of the system and then allocated.
4. Delete object
Void rt_object_delete (rt_object_t object)
Delete an object, first of all, it will do the separation of the object, and then release the corresponding memory space.
The design idea of rtthread is object-oriented, which makes the development highly coupled, so when adapting to different bsp packages, we can do well the interface of bsp without modifying the kernel. This kind of design is very ideal. Whether we write bare metal programs or use operating system design programs, we should have this kind of object-oriented idea. The stability of the program designed in this way is more reliable.
After reading the above, do you have any further understanding of how to analyze the idea of RT-Thread object-oriented programming? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.