Home > Software engineering >  A runtime dynamically add a class member variables
A runtime dynamically add a class member variables

Time:09-27

For example, we design a staff of two members of the class has a name and age, when the user runs the user was added to the height and weight, we use how to save the object serialization to save time? Or have other better solution to this problem?

CodePudding user response:

Define a format, such as the front is showed that the height, weight, followed by the corresponding data

CodePudding user response:

C + + is a strongly typed language, and don't like c and JAvA reflection, well dynamic, even if it benefits and is worth but also bring trouble

CodePudding user response:

refer to the second floor of HDT reply:
c + + is a strongly typed language, and don't like c and JAvA reflection, well dynamic, even if it is not for the benefits of the trouble


Does not restrict the c + + language, this problem can solve any other languages?

CodePudding user response:

reference 1st floor oyljerry response:
define a format, such as is showed in front of the height, weight, followed by the corresponding data


The two members are new to add a user, the new requirement is that we all gave him a new version? Can't runtime extension?



CodePudding user response:

Personally, what to cover a specific type attributes, such as certain things should be design,
If in the later to add these things without authorization, the feeling is in the blind to write!

CodePudding user response:

reference 5 floor HDT reply:
individual thinks, what to cover a specific type attributes, such as certain things should be design,
If in the later to add these things without authorization, the feeling is in the blind to write!

If the customer request to at run time can dynamically add class members that we should be how to design the class? What is a good way?

CodePudding user response:

Should you need is a database,

CodePudding user response:

Derived when adding a new class, serialized
Keep calling the superclass serialize itself serialization
Calls itself to serialize the superclass serialization

Or handle serialization, add a name to each data, according to the data read and write, so stronger scalability
  • Related