简单的解释PHP OOP与过程? [英] simple explanation PHP OOP vs Procedural?

查看:88
本文介绍了简单的解释PHP OOP与过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习PHP,并想获得有关OOP和过程的想法.我还阅读了其他有关OOP与程序的博客和教程,但我仍然不理解这种方法.

I would like to learn PHP and want to get an Idea about OOP and Procedural. I read some other blogs and tutorials about OOP vs Procedural but I still can't understand the approach.

OOP与程序性

  1. 我应该学习什么?
  2. 代码有什么区别?有什么影响?
  3. PHP框架如何帮助OOP? (我想学习CodeIgniter)
  4. 程序是否需要框架?

我真的很想知道两者的代码区别,我对OOP的理解是您创建了一个类似的类并且可以访问. (我不知道那是正确的.)

I really want to know the code difference of the both, my understanding of OOP is you create a class like and it can be access. (I dunno if thats correct).

谢谢!

推荐答案

背景:您要求提供一个简单的解释",该解释建议:

Background: You asked for a "simple explanation" which suggests:

  1. 您想要一个无聊的概述,没有行话
  2. 您想要可以帮助您从一开始学习的东西
  3. 您发现没有两个人以相同的方式回答问题,这很令人困惑.这就是您在这里要求简单说明的原因.是吗?
  1. You want a no-nonsense overview without jargon
  2. You want something that will help you learn from the beginning
  3. You have discovered that no two people ever answer the question the same way, and it's confusing. That's the reason you are here asking for a simple explanation. Yes?

简短的否定答案:

  1. 许多介绍性解释很快就跳入"OOP现实世界"示例中.这些往往会使人迷惑而不止是帮助,所以暂时不要理会.
  2. 您可以将源代码简单地视为功能的块",而这些功能恰好被保存到单个文件中.
  3. 组织这些块"有不同的方法;取决于编程语言的惯例,开发人员的背景和培训,或者仅仅是普通的个人喜好.
  4. OOP和过程编程只是用于组织和排列代码块"的两种主要公认方法.

长时间无人回答:

过程式操作与面向对象操作只是计算机编程的基本问题的一个方面:如何使您的代码易于理解和如何轻松地维护.您实际上可以编写遵循OOP某些原理的过程"代码,因此两者不一定是相反的.

Procedural vs OOP is just one aspect of a fundamental issue of computer programming: how to make your code easy to understand and a piece of cake to professionally maintain. You can actually write "Procedural" code that follows some of the principles of OOP, so the two are not necessarily opposites.

一旦您学习了其他面向对象的编程语言,您的理解就会真正增强其中,PHP是新手".

Your understanding will really grow once you learn other object-oriented programming languages, among which, PHP is a "new kid on the block".

以下是您在学习过程中将学到的内容的简要概述:

  • 您可以编写执行有用任务
  • 的PHP源代码.
  • 您可以将有用的任务组织成代码的块"
  • 您可以将代码的块"独立于保存文件的单个文件来考虑
  • 有时候,这些块"代码会根据您传入的参数而有所不同
  • 接受参数的代码块称为函数"
  • 功能可以一起分块" ,并且有不同的方法:
    • 例如:您可能只有一个大PHP文件,其中包含您一生中编写的所有功能,并且按功能名称按字母顺序列出
    • 例如::您可能有多个PHP文件,这些文件的功能按主题分块在一起(例如,用于执行基本字符串操作的功能,用于处理数组的功能,用于文件输入/输出的功能,等)
    • You can write PHP source code that does useful tasks
    • You can organize useful tasks into "chunks" of code
    • You can think of "chunks" of code independently of the individual files where they are saved
    • Sometimes those "chunks" of code will behave differently based on parameters you pass in
    • Chunks of code that accept parameters are called "Functions"
    • Functions can be "chunked" together, and there are different ways of doing this:
      • For example: you could have just one big PHP file with all the functions you have ever written in your entire life, listed in alphabetical order by function name
      • For example: you could have multiple PHP files with functions that are chunked together by subject matter [e.g., functions for doing basic string manipulation, functions for processing arrays, functions for file input/output, etc]

      一个类可以看作是方法属性

      • 方法 是与逻辑相关的简单函数以某种有意义的方式互相交流. 方法"和功能"这两个词基本上是同一件事的两个不同术语.
      • 属性只是与类相关的数据值.这些值是有意非隔离于任何单个函数的值,因为该类中的多个函数应该可以访问它们.
        • 例如:如果您的课程中有很多用于做天文学的方法,则该类的属性可能是所有天文学方法都需要知道的某些著名数字的值(例如Pi,光速,特定行星之间的距离等).
        • methods are simply functions that are logically related to one another in some meaningful way. The words "method" and "function" are basically two different terms for the same thing.
        • properties are simply data values that are related to the class. These are values that are intentionally non-isolated to any individual function, because more than one of the functions in the class should have access to them.
          • For example: if your class has a bunch of methods for doing astronomy, properties of the class might be the values for certain famous numbers that all astronomy methods need to know about (like Pi, the speed of light, the distance between specific planets, etc.).

          一个类很有用,因为它允许您以一种易于理解,使用和维护的方式在高水平上组织代码.

          A Class is useful because it allows you to organize your code at a very high level in a way that makes it easy for you to understand, use, and maintain.

          这篇关于简单的解释PHP OOP与过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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