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

  • Expert C++
  • Vardan Grigoryan Shunguang Wu
  • 158字
  • 2021-06-24 16:34:00

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.

主站蜘蛛池模板: 商城县| 青河县| 青龙| 阜新| 利川市| 宣威市| 兴隆县| 周至县| 和林格尔县| 花莲市| 龙井市| 石楼县| 林西县| 陵川县| 赣榆县| 安远县| 义乌市| 铁力市| 康平县| 雷山县| 瓦房店市| 滨州市| 惠水县| 大同县| 沁水县| 沾益县| 拜泉县| 方城县| 建湖县| 天台县| 德惠市| 当涂县| 临朐县| 从江县| 九江市| 同仁县| 石狮市| 湄潭县| 张掖市| 河东区| 肃北|