考虑C++中的接口是为了"the data"和"the program"之间的通信是否合理?
Is it reasonable to consider the interface in C++ is for the communication between "the data" and "the program"?
在 page 557 上,“C++ Primer Plus by Stephen Prata”一书说
OOP emphasizes how a program represents data.The first step toward
solving a programming problem by using the OOP approach is to describe
the data in terms of its interface with the program, specifying how
the data is used. Next, you need to design a class that implements the
interface.Typically, private data members store the information,
whereas public member functions,also called methods, provide the only
access to the data.The class combines data and methods into one
unit,and the private aspect accomplishes data hiding.
这里是不是指“数据”,也就是说接口是为了“数据”和“程序”之间的通信?
是的,“它”在该上下文中的意思是“数据的接口”。
另一种看待它的方式是,对象是函数局部数据和整个程序全局数据之间的中间值。有时一组函数共享数据很方便,因此这些函数和数据被组合到一个对象中。为了保证数据的一致性,其他函数不应该访问它,所以数据是私有的,所有来自其他代码的访问都需要通过对象的成员函数,这成为数据和其余部分之间的接口程序。
一个对象的所有常规函数都应该读取或修改数据,否则将它们放在同一个对象中没有意义。静态方法是一个例外,因为它们是纯函数,输出仅从输入产生。它们应该以某种方式与其他函数的输入或输出相关联才有意义,但我不会将它们算作界面的一部分。
Data 指的是您需要保存的任何类型的信息,它可能不仅是纯粹的数据,还可能是您的实现可能需要的其他对象,例如指针或引用其他类、定义等
Interface 指的是访问和处理 data 或从中计算出的任何结果的方式。应仔细设计接口以公开最少数量的必要方法。
在 page 557 上,“C++ Primer Plus by Stephen Prata”一书说
OOP emphasizes how a program represents data.The first step toward solving a programming problem by using the OOP approach is to describe the data in terms of its interface with the program, specifying how the data is used. Next, you need to design a class that implements the interface.Typically, private data members store the information, whereas public member functions,also called methods, provide the only access to the data.The class combines data and methods into one unit,and the private aspect accomplishes data hiding.
这里是不是指“数据”,也就是说接口是为了“数据”和“程序”之间的通信?
是的,“它”在该上下文中的意思是“数据的接口”。
另一种看待它的方式是,对象是函数局部数据和整个程序全局数据之间的中间值。有时一组函数共享数据很方便,因此这些函数和数据被组合到一个对象中。为了保证数据的一致性,其他函数不应该访问它,所以数据是私有的,所有来自其他代码的访问都需要通过对象的成员函数,这成为数据和其余部分之间的接口程序。
一个对象的所有常规函数都应该读取或修改数据,否则将它们放在同一个对象中没有意义。静态方法是一个例外,因为它们是纯函数,输出仅从输入产生。它们应该以某种方式与其他函数的输入或输出相关联才有意义,但我不会将它们算作界面的一部分。
Data 指的是您需要保存的任何类型的信息,它可能不仅是纯粹的数据,还可能是您的实现可能需要的其他对象,例如指针或引用其他类、定义等
Interface 指的是访问和处理 data 或从中计算出的任何结果的方式。应仔细设计接口以公开最少数量的必要方法。