当前位置: 首页 > news >正文

C++ Primer(第5版)- Chapter 7. Classes -001

In C++ we use classes to define our own data types. By defining types that mirror concepts in the problems we are trying to solve, we can make our programs easier to write, debug, and modify.

在 C++语⾔中,我们使⽤类定义⾃⼰的数据类型(data types)。通过定义新的类型来反映待解决问题中的各种概念,可以使我们更容易编写、调试和修改程序。

This chapter continues the coverage of classes begun in Chapter 2. Here we will focus on the importance of data abstraction, which lets us separate the implementation of an object from the operations that that object can perform. In Chapter 13 we’ll learn how to control what happens when objects are copied, moved, assigned, or destroyed. In Chapter 14 we’ll learn how to define our own operators.

本章是第2章关于类的话题的延续,主要关注(focus on数据抽象(data abstraction的重要性,数据抽象能帮助我们将对象的具体实现(the implementation of an object与对象所能执⾏的操作分离开来。第13章将讨论如何控制对象拷贝(copy、移动(move、赋值(assign和销毁(destroy等⾏为。在第14章中我们将学习如何⾃定义运算符。

The fundamental ideas behind classes are data abstraction and encapsulation. Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation. The interface of a class consists of the operations that users of the class can execute. The implementation includes the class’ data members, the bodies of the functions that constitute the interface, and any functions needed to define the class that are not intended for general use.

类的基本思想(fundamental ideas)是数据抽象(data abstraction)和封装(encapsulation)。数据抽象是⼀种依赖于(rely on)接口(interface)和实现(implementation)分离的编程(以及设计)技术。类的接口包括(consist of)⽤户所能执⾏的操作;类的实现则包括(include)类的数据成员(the class’ data members)、负责接口实现(constitute the interface)的函数体(bodies of the functions)以及定义类所需的各种私有函数(that are not intended for general use)。

Encapsulation enforces the separation of a class’ interface and implementation. A class that is encapsulated hides its implementation—users of the class can use the interface but have no access to the implementation.

封装(Encapsulation)实现了(enforce)类的接口(interface)和实现(implementation)的分离(separation)。封装后(that is encapsulated)的类隐藏了(hide)它的实现细节(implementation)。也就是说,类的⽤户(users of the class)只能使⽤接口(interface)⽽⽆法访问(have no access to)实现部分(the implementation)。

A class that uses data abstraction and encapsulation defines an abstract data type. In an abstract data type, the class designer worries about how the class is implemented. Programmers who use the class need not know how the type works. They can instead think abstractly about what the type does.

类要想实现数据抽象(data abstraction)和封装(encapsulation),需要⾸先定义⼀个抽象数据类型(an abstract data type)。在抽象数据类型中,由类的设计者负责考虑(worry about)类的实现过程。使⽤该类的程序员则只需要抽象地思考(think abstractly about)类型做了什么,⽽⽆须了解类型的⼯作细节 。

http://www.dtcms.com/a/276483.html

相关文章:

  • 基于Java Web的二手房交易系统开发与实现
  • 利用docker部署前后端分离项目
  • 【QT】多线程相关教程
  • Linux中使用快捷方式加速SSH访问
  • 通俗范畴论13 鸡与蛋的故事番外篇
  • 2D转换之缩放scale
  • 《P2052 [NOI2011] 道路修建》
  • JavaScript:移动端特效--从触屏事件到本地存储
  • (LeetCode 面试经典 150 题 )3. 无重复字符的最长子串 (哈希表+双指针)
  • 两数之和 https://leetcode.cn/problems/two-sum/description/
  • 基于hugo的静态博客站点部署
  • 苹果公司高ROE分析
  • Druid 连接池使用详解
  • 基于 SpringBoot+Uniapp 易丢丢失物招领微信小程序系统设计与实现
  • BugBug.io 使用全流程(202507)
  • Kubernetes持久卷实战
  • zcbus使用数据抽取相当数据量实况
  • 8. JVM类装载的执行过程
  • hive的索引
  • DBeaver连接MySQL8.0报错Public Key Retrieval is not allowed
  • C语言基础知识--位段
  • UE制作的 AI 交互数字人嵌入到 Vue 开发的信息系统中的方法和步骤
  • 【MaterialDesign】谷歌Material(Google Material Icons) 图标英文 对照一览表
  • AI问答:成为合格产品经理所需能力的综合总结
  • dify工作流1:快速上手ai应用
  • 计算机毕业设计Java停车场管理系统 基于Java的智能停车场管理系统开发 Java语言实现的停车场综合管理平台
  • 网络通信模型对比:OSI与TCP/IP参考模型解析
  • 《Java Web程序设计》实验报告三 使用DIV+CSS制作网站首页
  • ServiceNow Portal前端页面实战讲解
  • [案例八] NX二次开发长圆孔的实现(支持实体)