官术网_书友最值得收藏!

Understanding objects

Most of the time, we operate with a collection of data grouped under a certain name, thus making an abstraction. Variables such as is_military, speed, and seats don't make much sense if they're perceived separately. Grouping them under the name with spaceship changes the way we perceive the data stored in the variables. We now refer to the many variables packed as one single object. To do so, we use abstraction; that is, we collect the individual properties of a real-world object from the perspective of the observer. An abstraction is a key tool in the programmer's toolchain as it allows them to deal with complexity. The C language introduced the struct as a way to aggregate data, as shown in the following code:

struct spaceship {
bool is_military;
int speed;
int seats;
};

Grouping data is somewhat necessary for object-oriented programming. Each group of data is referred to as an object.

主站蜘蛛池模板: 麻江县| 开封县| 巩留县| 兴宁市| 富锦市| 保靖县| 都江堰市| 琼中| 台东县| 霸州市| 通河县| 黑龙江省| 柳林县| 浑源县| 嵊泗县| 舒城县| 海门市| 西青区| 秦安县| 吴堡县| 陆丰市| 赣榆县| 连山| 龙海市| 霍邱县| 凤翔县| 吉首市| 汪清县| 吐鲁番市| 昭觉县| 朔州市| 梁平县| 黑山县| 沾益县| 大石桥市| 新兴县| 昆山市| 甘泉县| 会东县| 岳普湖县| 额济纳旗|