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

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.

主站蜘蛛池模板: 连平县| 泰宁县| 嘉禾县| 上饶市| 泰宁县| 密云县| 东乡族自治县| 岫岩| 徐州市| 旅游| 五河县| 曲麻莱县| 南丹县| 台北县| 油尖旺区| 济源市| 固阳县| 台前县| 乌兰浩特市| 江北区| 天津市| 富锦市| 冷水江市| 阿鲁科尔沁旗| 青川县| 惠来县| 宝鸡市| 玉溪市| 台中市| 合肥市| 闵行区| 昌图县| 永顺县| 宁陵县| 泰和县| 株洲县| 苏尼特右旗| 科技| 柯坪县| 泾源县| 米脂县|