什么是面向对象的编程? [英] What's Object Oriented Programming?

查看:77
本文介绍了什么是面向对象的编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用面向对象的编程语言进行编程非常陌生. 那么,请问您如何向孩子解释面向对象编程的概念?

I'm pretty new to programming with Object Oriented Programming Languages. So please how do you explain the concept of object oriented programming to a kid?

推荐答案

您需要了解的一些关键概念是面向对象编程(OOP)的对象和类.这是一个非常基本的解释,但是希望可以帮助您了解其他文档.

Some of the key concepts you need to understand are objects and classes for Object Oriented Programming (OOP). This is a very basic explanation, but hope can help you understand other documentation.

让我们将OOP与巧克力模具进行比较.要做一些巧克力的第一件事,就是要建立它的模具.模具将对未来的巧克力具有一些特性,例如形状,大小等,具体取决于您将如何制作未来的巧克力.

Let's compare OOP with chocolate molds. The first thing you have to do to make some chocolates, you need to build its mold. The mold will have some characteristics for the future chocolates like shape, size, etc. depending on how you create the mold the future chocolates will be.

模具准备好后,您就可以制作巧克力了.所有巧克力都具有模具特征,具有相同的形状和大小,但是最终的巧克力上会有一些特征,您可以修改,例如,巧克力的类型(黑色或白色),您也可以用坚果,杏仁,花生等不同的东西填充巧克力.

Once the mold is ready you can create the chocolates. All chocolates will take the mold characteristics, will have the same shape and size, but there will be some characteristics on the resultant chocolates that you will be able to modify like i.e. the type of chocolate (black or white), you will also be able to fill in the chocolate with different things like nuts, almonds, peanuts, etc.

因此,以此类推,模具是分类的,它们将调节所得的巧克力.巧克力是基于类创建的对象.对象也称为类的实例.

So, in this analogy, the mold are classes and they will condition the resultant chocolates. Chocolates are objects created based on a class. Objects are also called instances of a class.

类具有属性或变量,以此类推,属性为:Chocolate_type :(黑/白),Chocolate_filler(坚果,杏仁,花生等),elaboration_date,due_date.

Classes have attributes or variables, on this analogy the attributes would be: chocolate_type: (black/white), chocolate_filler (nuts, almonds, peanuts, nothing, etc), elaboration_date, due_date.

创建新对象时,您将必须定义它们的每个属性,例如: 巧克力1:黑色,充满坚果,精心制作:2016年1月1日,日期:2016年3月1日 Chocolate2:白色,内装杏仁,精心制作:2016年1月1日,日期:2016年3月1日 Chocolate3:黑白相间,装满坚果,详细说明:2016年1月1日,日期:2016年3月1日

When a new object is created you will have to define each one of their attributes like: chocolate1: black, filled with nuts, elaborated: 01/01/2016, dd: 03/01/2016 chocolate2: white, filled with almonds, elaborated: 01/01/2016, dd: 03/01/2016 chocolate3: black&white, filled with nuts, elaborated: 01/01/2016, dd: 03/01/2016

巧克力类推

使用字符串,布尔值,整数等变量定义类的属性.

The attributes of a class are defined using variables such as string, boolean, integer, etc.

每个对象还可以具有定义其行为(每个对象可以执行什么动作)的方法/功能.

Also each object can have methods/functions that will define their behavior (what actions each object can perform).

https://en.wikipedia.org/wiki/面向对象编程

希望,这个非常基本的解释对您有所帮助.

Hope, this very basic explanation helped you.

这篇关于什么是面向对象的编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆