Application framework Design (3): RuntimeClass and serialization

Source: Internet
Author: User

The root of the SW system is sobject, as its name implies, an abstraction of objects in the universal sense. Its main support is as follows:

Run time class information (RuntimeClass)

Runtime class information is an extremely important part of classical program structure. MFC, VCL, OWL, and turbovision all support run-time-time class information. It is probably the only thing in the Classic object class that is more practical. It is also the most confusing place for the object class. To put it simply, runtime-type information has two main uses:

A) Creating objects

b) Determine the type of object

In fact, the implementation mechanism of RuntimeClass is not mysterious. It is simply through class registration to associate the class name with its parent class, instance creation function.

SW System Running time class information is defined as:

typedef SObject * (*FNBUILDER)();
struct SRuntimeClass
{
LPCTSTR m_lpszClassName;// 类名
SRuntimeClass * m_lpBaseClass;// 父类
FNBUILDER m_fnCreator;// 实例创建
SRuntimeClass *m_lpPrevClass;
};

Each of the SW system's classes should have a Sruntimeclass instance to describe the class. You can use __typeid (class) to locate the RuntimeClass information for this class. This macro is exactly the same as the MFC Runtime_class (CLASS) macro.

Note that Sruntimeclass has a member M_lpprevclass, which is only used to maintain runtimeclass linked lists in the system. This allows the user to query the Run-time class information of a class by the name of the class, and to create an object of that class. For example, the following serialization techniques need to do this.

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.