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

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.xdnf.cn/news/15238.html

相关文章:

  • AI大模型(七)Langchain核心模块与实战(二)
  • 嵌入式领域编码合集(为什么中文会乱码)
  • (一)一阶数字低通滤波器---原理及其推导
  • web网站无法抓包排查;burp无法抓包情况
  • 实用技巧 Excel 与 XML互转
  • 鸿蒙进程通信的坑之ServiceExtensionAbility
  • 【大模型】深度学习之神经网络
  • Scrapy爬虫中间件核心技术解析:定制化爬虫的神经中枢
  • 9.2 埃尔米特矩阵和酉矩阵
  • 张量拼接操作
  • Git系列--4.Git分支设计规范
  • 深大计算机游戏开发 实验二
  • 8. JVM类装载的执行过程
  • 【读书笔记】《C++ Software Design》第二章:The Art of Building Abstractions
  • c++反射实现
  • Python ExcelWriter详解:从基础到高级的完整指南
  • 网络安全初级--搭建
  • python的婚纱影楼管理系统
  • Redis Geospatial 功能详解及多边形包含判断实现
  • SpringAI实现聊天记录保存到MySQL
  • 「日拱一码」025 机器学习——评价指标
  • Spring 框架中的设计模式:从实现到思想的深度解析
  • C++类模板继承部分知识及测试代码
  • 在 Android 库模块(AAR)中,BuildConfig 默认不会自动生成 VERSION_CODE 和 VERSION_NAME 字段
  • Linux之Zabbix分布式监控篇(一)
  • 云原生技术与应用-生产环境构建高可用Harbor私有镜像仓库
  • 网络通信模型对比:OSI与TCP/IP参考模型解析
  • BGP 路由优选属性(7)【MED】官方考试综合实验题【bgp】【acl】【ip-prefix】【route-policy】【icmp 环路】精讲
  • Frida绕过SSL Pinning (证书绑定)抓包;Frida注入;app无法抓包问题解决。
  • 哔哩哔哩第三方TV-BBLL最新版