当前位置: 首页 > 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.lryc.cn/news/586435.html

相关文章:

  • Web学习笔记3
  • Windows环境下JS计时器精度差异揭秘
  • Qt:QCustomPlot类介绍
  • LangChain极速入门:用Python构建AI应用的新范式
  • zcbus使用数据抽取相当数据量实况
  • Scrapy爬虫中间件核心技术解析:定制化爬虫的神经中枢
  • CCS-MSPM0G3507-2-基础篇-定时器中断
  • 69 局部变量的空间分配
  • 通俗范畴论13 鸡与蛋的故事番外篇
  • C++类模板继承部分知识及测试代码
  • Golang操作MySQL json字段优雅写法
  • Hap包引用的Hsp报签名错误怎么解决
  • 【数据分析】03 - Matplotlib
  • LangChain 内存(Memory)
  • Java 大视界 -- Java 大数据机器学习模型在电商用户复购行为预测与客户关系维护中的应用(343)
  • C语言基础知识--动态内存管理
  • AD芯片(模数转换器)的有效位数(ENOB)
  • scrapy项目开发流程
  • C++中的容斥原理
  • Springboot aop面向切面编程
  • 虚拟商品交易维权指南:数字经济时代的消费者权益保护
  • Boost.Asio 中的定时器类 steady_timer
  • python如何把两张图片拼成一张
  • Gitee Push 失败 7 日谈:每天一个踩坑故事
  • Java中的方法传参机制
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘multiprocessing’问题
  • QT跨平台应用程序开发框架(6)—— 常用显示类控件
  • 使用FastAdmin框架开发
  • Java项目2——增强版飞机大战游戏
  • 【极客日常】后端任务动态注入执行策略的一种技术实现