Object-oriented Programming in PHP: Methods for developing large PHP projects (iii) (reproduced) _php tutorial

Source: Internet
Author: User
Object-oriented Programming in PHP: How to develop a large PHP project (iii) Author: Luis Argerich Translator: Limodou overloads (unlike overrides) are not supported in PHP. In OOP, you can overload a method to implement two or more methods with the same name, but with different numbers or types of arguments (this depends on the language).   PHP is a loosely typed language, so it does not work with type overloading, but overloading with different number of parameters does not work. Sometimes overloading constructors in OOP is great, so you can create objects in different ways (passing different numbers of parameters). The trick to implementing it in PHP is:-------------------------------------------------------------------------------- $name (); Note that $this->name () is generally wrong, but here $name is the name of the method that will be called} function Myclass1 ($x) {code;} function Myclass2 ($x, $y) {code;}}   ?>--------------------------------------------------------------------------------by additional processing in the class, using this class is transparent to the user: $obj 1=new Myclass (1); Will call Myclass1 $obj 2=new Myclass; Will call Myclass2 sometimes this is very useful. Polymorphic polymorphism is the ability of an object to decide which object to invoke in the runtime, depending on the object parameters passed. For example, if you have a figure class, it defines a draw method. and derive the circle and rectangle classes, in which you override the Draw method, you may also have a function that expects to use a parameter x, and can call $x->draw ().   If you have polymorphism, calling which draw method depends on the type of object you pass to the function. Polymorphism in an interpreted language like PHP (imagine a C + + compiler generating such code, which method should you call?) You also don't know what type of object you have, well, it's not the point, it's very easy and natural. So PHP certainly supports polymorphism. -------------------------------------------------------------------------------- Draw (); } $obj =new Circle (3,187); $obj 2=new Rectangle (4,5); $board->nicedrawing ($obj); The draw method that will call Circle $board->nicedrawing ($obj 2); The draw method of rectangle will be called?>-------------------------------------------------------------------------------- Object-oriented Programming with PHP some "purists (purists)" might say that PHP is not a true object-oriented language, which is true. PHP is a mixed language, you can use OOP, or you can use traditional procedural programming.   However, for large projects, you might want to use pure OOP in PHP to declare classes, and only use objects and classes in your project. As projects grow larger, using OOP can be helpful, and OOP code is easy to maintain, easy to understand and reuse. These are the foundations of software engineering. Applying these concepts to Web-based projects is the key to future site success. Transfer from phpbuilder.com

http://www.bkjia.com/PHPjc/532299.html www.bkjia.com true http://www.bkjia.com/PHPjc/532299.html techarticle object-oriented programming in PHP: How to develop a large PHP project (iii) Author: Luis Argerich Translator: Limodou overloads (unlike overrides) are not supported in PHP. In OOP, you can overload a ...

  • 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.