[Original] Two Kinds of encapsulation thinking, original encapsulation thinking
Encapsulate student information in one structure:
1. Thinking 1
Struct Student_info
{
Vector <string> name;
Vector <double> score;
};
Student_info std;
Stu. name. push_back (name );
Stu. score. push_back (score );
2. Thinking 2
Struct Student_info
{
String name;
Double score;
};
Vector <Student_info> std_vec;
Student_info std;
Std. name = name;
Std. score = score;
Std_vec.push_back (std );
Thinking 1 is like buying a bunch of components, each of which is encapsulated in a bag.
Thinking 2 is like splicing the various components we bought into the products we want, and then encapsulating them in a bag.
Obviously, the encapsulation process of thinking 2 is complicated:
Vector <Student_info> std_vec;
Student_info std;
Std. name = name;
Std. score = score;
But it is more convenient to use, isn't it?
Std_vec.push_back (std );
Obviously, thinking 2 is more insightful ~~!!