类.重点是什么? [英] Classes. What's the point?

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

问题描述

我对使用PHP进行OOP还是比较陌生,我编写了一些基本脚本,但没什么令人印象深刻.我真正从中获得的所有好处是,仅对函数进行收集并include进行操作可能会更容易.

I'm fairly new to OOP in PHP, I've made a couple of basic scripts but nothing impressive. All I've really taken from it is that it would probably be easier just make a collection of functions and include them.

类的结构似乎只会混淆原本简单的过程.并且将所有内容整理到一个类中并没有真正添加任何功能.

The structure of classes seems to just confuse what was otherwise a simple process. And in collating everything into a class it doesn't really add any functionality.

所以我很明显地缺少一些东西.有人可以解释通过创建类添加的功能

So I'm clearly missing something. Could someone explain what functionality is added by creating classes

推荐答案

类是面向对象设计(分别是编程和分析)的概念,它们用于封装数据和方法 >.

Classes are a notion of object-oriented design (and programming and analysis, respectively), where they are used to encapsulate data and methods.

其他面向对象的编程技术可能包括诸如

Other object-oriented programming techniques may include features such as

  • 信息隐藏,
  • 数据抽象,
  • 封装
  • 模块化,
  • 多态和
  • 继承力

摘自文章.. 撰写超级可读代码的前15条最佳做法:

面向对象的编程可以帮助您创建结构良好的代码.但这并不意味着您需要完全放弃过程编程.实际上创建两种样式的混合可能会很好.

Object oriented programming can help you create well structured code. But that does not mean you need to abandon procedural programming completely. Actually creating a mix of both styles can be good.

来自 http://java.sun.com/docs /books/tutorial/java/concepts/class.html :

在现实世界中,您经常会发现许多同一种物体.可能还有成千上万的其他自行车,都具有相同的品牌和型号.每辆自行车都是根据相同的设计图制造的,因此包含相同的组件.用面向对象的术语来说,您的自行车是称为自行车的一类对象的实例.类是从中创建单个对象的蓝图.

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

最后,简要介绍一下 youtube视频和面向对象的编程范式...

Finally, a short youtube video about the differences between the procedural and object-oriented programming paradigm ...

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

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