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

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.

主站蜘蛛池模板: 南昌县| 舟曲县| 吉安县| 琼结县| 宜良县| 电白县| 上饶县| 连山| 达孜县| 南乐县| 新疆| 宽城| 兴安县| 福海县| 东辽县| 昌宁县| 陵水| 武夷山市| 恩平市| 西乡县| 伊川县| 施甸县| 青神县| 垣曲县| 临猗县| 邯郸县| 车险| 天镇县| 商都县| 阳谷县| 乐平市| 柏乡县| 德格县| 虞城县| 连江县| 繁峙县| 平果县| 沅陵县| 德兴市| 双城市| 高平市|