类。重点是什么? [英] Classes. Whats the point?

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

问题描述

我在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


  • 信息隐藏,

  • 数据抽象,

  • 封装,

  • 模块化,

  • 多态性和

  • 继承

  • information hiding,
  • data abstraction,
  • encapsulation,
  • modularity,
  • polymorphism and
  • inheritance

://net.tutsplus.com/tutorials/html-css-techniques/top-15-best-practices-for-writing-super-readable-code/rel =nofollow noreferrer> top-15-best-practices for-writing-super-readable-code :

From an article .. top-15-best-practices-for-writing-super-readable-code:


面向对象编程可以帮助您创建结构良好的代码。但这并不意味着你需要完全放弃程序编程。

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 video 关于程序性和面向对象编程范式之间的差异...

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

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

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