Object-oriented and process-oriented programming methods in PHP _php tutorial

Source: Internet
Author: User
   Introduction
"Real geniuses have the ability to correctly assess uncertain, risky and contradictory information. --Churchill "
  
When working with many programming languages, you can usually only use one of the object-oriented or process-oriented programming methods. In PHP (which is now the mainstream development language), you are free to choose or mix. The vast majority of PHP (now mainstream development language) programmers use a process-oriented approach because parsing the Web page itself is very "procedural" (from one label to another). Embedding the Process code in HTML is straightforward and natural, so PHP (which is now the mainstream development language) is often used this way.
  
If you are new to PHP (as the current mainstream development language), writing code in a process-oriented style is probably your only option. But if you regularly go to the forums and newsgroups of PHP (which is now the mainstream development language), you should see articles about "objects". You may also have seen a tutorial on how to write object-oriented PHP code, which is now a mainstream development language. Or you might have downloaded some out-of-the-box libraries and tried to instantiate objects and use class methods-although you might not really understand why these classes work, or why you need to use object-oriented methods to implement functionality.
  
Should you use the "Object-oriented" style or the "process-oriented" style? Each side has its supporters. Such arguments as "objects are inefficient" or "objects are very good" are also heard. This article does not attempt to easily determine which of the two methods has the absolute advantage, but to find out the pros and cons of each method.
  
The following are code examples for procedural styles:
  
   Print "Hello, world.";
?>
  
The following is an example of an object-oriented style code:
  
   Class HelloWorld {
function Myprint () {
Print "Hello, world.";
}
}
$myHelloWorld = new HelloWorld ();
$myHelloWorld->myprint ();
?>
  
If you want to learn some basics of "object-oriented", use Google search, which has a lot of wonderful articles on the web.
  
   who writes code like this?
To understand why this topic has become a flashpoint for the forum water fights, let's look at some of the more extreme examples of each faction. Let's look at "Process Mania" and "Object Mania". See if their point of view sounds a little familiar.
  
   Process Mania
The process mania was criticized by computer teachers in class because it did not use a more abstract approach to implementation. and support the view of the process-oriented "It can work!" "does not improve its programming level and grade. After graduation they may find a job, write drivers, file systems or other bias-biased programming, focusing their attention on speed and the refinement of the code.
  
The extreme example of "process Mania" is resisting the object and resisting abstraction. They are always thinking about how to make the program run faster and don't care if someone can read their code. They often regard programming as a contest rather than as a team activity. In addition to PHP (which is now the mainstream development language), their favorite programming language is C and assembler. In the world of PHP, which is now the mainstream development language, they may develop PECL modules and contribute efficient code.
  
   Object Mania
Object fanatics are keen to write code at any time using object-oriented styles. They did not really consider whether this approach would affect the execution efficiency of the program. Sometimes it is felt that they enjoy abstract design concepts rather than realistic code. They are often likely to be project managers or document writers.
  
Object enthusiasts point out that without abstract design methods we are still programming with 0 and 1. They like to use pseudo code to describe the problem. Extreme examples are object fanatics who even know that sometimes sacrifice efficiency still uses objects. In addition to PHP (which is now the mainstream development language), their favorite language is Java and Smalltalk. In the World of PHP (which is now the mainstream development language), they may develop pear modules that contribute to documenting very good, easy-to-maintain code.
  
   don't be extreme and sarcastic .
Do you know why the forums are always full of prejudices? Your experience, your attitude to new things may be the reason. As programmers, we need to constantly pay attention to these prejudices and learn new things with an open mind.
  
   What's your coding tendency?
Consider the preference or inclination to write PHP (as the current mainstream development language) code. Usually these preferences are somewhat obscure. Sometimes you may have the same preference in every project. I personally tend to be "classy", but I don't want to define what is "elegant" code here, which should appear in another article. However, the theoretical preferences are not necessarily suitable for actual projects-they are often a bias, on the contrary.

http://www.bkjia.com/PHPjc/508601.html www.bkjia.com true http://www.bkjia.com/PHPjc/508601.html techarticle Introduction "True Genius has the ability to correctly assess uncertain, risky and contradictory information." Churchill "When using many programming languages, you can usually only use object-oriented or polygon ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.