c语言面向对象编程中的类

Object oriented programming, OOP for short, aims to implement real world entities like inheritance, hiding and polymorphism in programming.

面向对象的编程,简称OOP,旨在在编程中实现诸如继承,隐藏和多态性之类的现实世界实体。

The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.

OOP的主要目的是将数据和对其进行操作的功能绑定在一起,以便除该功能外,代码的其他任何部分都无法访问此数据。

Let's learn about different characteristics of an Object Oriented Programming language.

让我们了解一下面向对象编程语言的不同特征。

目的: (Object:)

Objects are basic run-time entities in an object oriented system. Objects are instances of a class which are user defined data types.

对象是面向对象系统中的基本运行时实体。 对象是类的实例,是用户定义的数据类型。

class person
{char name[20];int id;
public:void getdetails(){}
};int main()
{person p1; //p1 is an object
}

Objects take up space in memory and have an associated address like a record in pascal or a structure or union in C.

对象占用内存中的空间,并具有关联的地址,例如pascal中的记录或C中的结构或联合。

When a program is executed the objects interact by sending messages to one another.

执行程序时,对象通过相互发送消息进行交互。

Each object contains data and code to manipulate the data. Objects can interact without having to know the details of each others' data or code. It's enough to know the type of message accepted and type of response returned by the objects.

每个对象都包含数据和用于操纵数据的代码。 对象可以进行交互,而不必知道彼此数据或代码的详细信息。 知道接受的消息类型和对象返回的响应类型就足够了。

类: (Class:)

A class is a blueprint of data and functions or methods. Class does not take any space.

类是数据,函数或方法的蓝图。 类不占用任何空间。

class class_name
{private://data members and member functions declarationspublic://data members and member functions declarationsprotected://data members and member functions declarations
};

Class is a user defined data type like structures and unions in C.

类是用户定义的数据类型,例如C中的结构和联合。

By default class variables are private, but in case of structure they are public. In the above example, person is a class.

默认情况下,类变量是私有的,但是在结构的情况下,它们是公共的。 在上面的示例中,person是一个类。

封装和数据抽象: (Encapsulation and Data abstraction:)

Wrapping up (combining) data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapping the class can access it. This insulation of the data from direct access by the program is called data hiding or information hiding.

将数据和功能包装(组合)为单个单元称为封装。 外界无法访问该数据,只有包装该类的那些函数才能访问它。 防止程序直接访问的这种数据隔离称为数据隐藏或信息隐藏。

Data abstraction refers to providing only needed information to the outside world and hiding implementation details.

数据抽象是指仅向外界提供所需的信息并隐藏实现细节。

For example, consider a class Complex with public functions getReal() and getImag(). We may implement the class as an array of size 2 or as two variables.

例如,考虑具有公共函数getReal()和getImag()的类Complex。 我们可以将类实现为大小为2的数组或两个变量。

The advantage of abstraction is that we can change implementation at any point and the users of the Complex class won’t be affected as our method interface remains same. Had our implementation been public, we would not have been able to change it.

抽象的优点是我们可以随时更改实现,并且由于我们的方法接口保持不变,因此不会影响Complex类的用户。 如果我们的实施是公开的,我们将无法对其进行更改。

遗产: (Inheritance:)

Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical classification.

继承是一个类的对象获取另一类的对象的属性的过程。 它支持层次分类的概念。

Inheritance provides reusability. This means that we can add additional features to an existing class without modifying it.

继承提供了可重用性。 这意味着我们可以在不修改现有类的情况下添加其他功能。

多态性: (Polymorphism:)

Polymorphism refers to the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the types of data used in the operation.

多态性是指采取多种形式的能力。 一个操作在不同情况下可能表现出不同的行为。 行为取决于操作中使用的数据类型。

C++ supports operator overloading and function overloading. Operator overloading is the process of making an operator exhibit different behaviors in different instances. Function overloading is using a single function name to perform different types of tasks. Polymorphism is extensively used in implementing inheritance.

C ++支持运算符重载和函数重载。 操作员重载是使操作员在不同情况下表现出不同行为的过程。 函数重载使用单个函数名来执行不同类型的任务。 多态被广泛用于实现继承。

动态绑定: (Dynamic Binding:)

In dynamic binding, the code to be executed in response to a function call is decided at runtime. C++ has virtual functions to support this.

在动态绑定中,将在运行时确定响应函数调用而执行的代码。 C ++具有支持此功能的虚函数。

讯息传递: (Message Passing:)

Objects communicate with one another by sending and receiving information to each other. A message for an object is a request that a procedure be executed and therefore it will invoke a function in the receiving object that generates the desired results.

对象通过相互发送和接收信息来相互通信。 对象的消息是对过程执行的请求,因此它将在接收对象中调用生成所需结果的函数。

Message passing involves specifying the name of the object, the name of the function and the information to be sent.

消息传递涉及指定对象的名称,函数的名称以及要发送的信息。

更多信息 (More information)

Object Oriented Programming Concepts: How to go from Zero to One with Objects

面向对象的编程概念:如何使对象从零变为一

How to Explain Object Oriented Programming Concepts to a 6 Year Old

如何向6岁的孩子介绍面向对象的编程概念

翻译自: https://www.freecodecamp.org/news/object-oriented-programming-in-c/

c语言面向对象编程中的类

c语言面向对象编程中的类_C ++中的面向对象编程相关推荐

  1. C语言面向对象编程的类是指,c语言面向对象编程中的类_C ++中的面向对象编程...

    c语言面向对象编程中的类 Object Oriented programming is a programming style that is associated with the concept ...

  2. java中object类怎么赋值_Java面向对象之Object类

    一.继承体系的老祖宗是Object类.(Object类是所有类的父类) 当我们不希望在程序中某些类被继承,某些方法被重写,某些数据被修订.就是final关键字闪亮登场的时候了. 一个类没有使用exte ...

  3. python 类中定义类_Python中的动态类定义

    python 类中定义类 Here's a neat Python trick you might just find useful one day. Let's look at how you ca ...

  4. java 在一个类中定义类_Java 中程序代码必须在一个类中定义,类使用( )关键字来定义。_学小易找答案...

    [填空题]每一个 else 子句都必须和它前面的一个距离它最近的 子句相对应. [单选题]有关类的说法,正确的是( ) [单选题]在JAVA中,无论测试条件是什么,下列( )循环体 将至少执行一次. ...

  5. c++中的模板_C ++中的模板

    c++中的模板 Templates in C++ are an abstract version of Generic Programming wherein the code is written ...

  6. java中 如果类c_Java中,如果类C是类B的子类,类B是类A的子类,那么下面描述正确的是( )。_学小易找答案...

    [单选题]社会意识是() [判断题]刘易斯认为,在发展中国家,经济发展应当追求最高精尖的技术.( ) [单选题]财务杠杆反映的是 [判断题]是否承认社会历史的规律性,是唯物史观和唯心史观的根本对立. ...

  7. c#中如何删除数组中的元素_C中的数组

    c#中如何删除数组中的元素 为什么我们需要数组? (Why do we need Arrays?) Consider the problem of storing 10 integers. The n ...

  8. js中没有类怎么玩转面向对象

    这是一篇文笔幽默风趣的文章里面的用通俗易懂的方法写出了 为什么在js 中没有class类却可以完成继承 转载地址:http://www.cnblogs.com/aishangJava/p/723268 ...

  9. c语言中优先级队列_C ++中的优先级队列

    c语言中优先级队列 A Priority Queue is a variant of a Queue such that it's elements are ordered based on thei ...

最新文章

  1. [Flex]Flex SDK 4(Gumbo)改善的Layout和Scroller(二)
  2. Golang之envconfig的使用
  3. 语音合成:模拟最像人类声音的系统
  4. DOM结点的渲染(attach)
  5. MySQL操作实战(三):表联结
  6. pdf各种处理 PDF 的实用代码:PyPDF2、PDFMiner、pdfplumber
  7. TypeScript 3.4 发布
  8. 学校计算机考察内容是什么意思,2019考研计算机复试四项考察内容分析及注意事项...
  9. MySQL与Oracle 差异比较之五存储过程Function
  10. Android查看应用签名方法
  11. java javaw 命令区别_java.exe和javaw.exe有什么区别
  12. 支付宝-沙箱环境配置和使用
  13. 人生若只如初见,碧海青天夜夜心
  14. Leetcode 1925. Count Square Sum Triples [Python]
  15. 顺口溜:国足欢迎你(贬)
  16. “大灯”到底指近光灯还是远光灯?
  17. 使用FTPClient封装FtpUtil
  18. python随机生成邮箱、自我介绍、地址、时间等
  19. linux 压缩固定大小,tar gz压缩文件为指定大小
  20. Go开发 之 容器(数组Array、切片slice、映射map、列表list)

热门文章

  1. Spark的安装和使用
  2. 编写五子棋的完整python代码_python制作简单五子棋游戏
  3. iOS 关于Blocks
  4. Javascript - prototype、__proto__、constructor
  5. service 与chkconfig
  6. 深入浅出WPF——x:Class详解
  7. 路由器配置实践 教你如何在Linux中三台主机两个网段互相通信
  8. exchange 2003配置ASSP 反垃圾邮件
  9. http_build_query用法
  10. Android:ViewPager为页卡内视图组件添加事件