PHP Oop-are you using OOP?

Source: Internet
Author: User
Tags php oop

Because it was written during lunch break, I am not very careful about it.

The main issue is the old-fashioned issue of OOP...

I have been working for two years and have some ideas about oop, But I 've rummaged through the introduction of OOP in major bookstores (like writing it by myself)

 
<?PHPClassCar {PublicGetname (){Return $ This->Name ;}PublicGetspeed (){Return $ This->Speed ;}}?>

This kind of thing is believed to only appear in the book.Code.. (Except for JavaBean)

Based on these ideas, I have the following code:

<? PHP  Class  Order {  Private _ Goodsarr = Array  ();  Public   Function  _ Construct (){}  /*  * @ Return goods {}  */       Public   Function Getgoods (){  //  Search for the product number goods_sn under the order          Foreach ( $ Goods_sn   As   $ Goods_sn  )  Array_push ( $ This -> _ Goodsarr, New Goods ( $ Goods_sn  ));  Return   $ This ->_ Goodsarr ;}}  Class  Goods {  Public   Function  Getname (){}}  $ Order1 = New Order ('anba01' );  $ Goodsarr = $ Order1 -> Getgoods ();  Foreach ( $ Goodsarr   As  $ Goods  ){  Echo   $ Goods -> Getname (). '<br>' ;} ?>

But this is contrary to the Code in project development.

 
   php   class   order {  Public   function  __ construct () {}  Public   function  getgoodsinfo ( Array  ('name', 'price'  )) { ///   organize data structures  }  $ order2  =  New  Order ('aanba02' );   echo   $ order2 -> getgoodsinfo ( array  ('price' ); ?> 

I personally think the first one is more in line with the object-oriented norms. But in actual development, it is often the second type.

Because it is not developed by one person, it can only be followed by mostProgramPersonnel. However, the reusability of such code is greatly reduced.

I have written the same function several times and wonder if you have supported my opinion. Welcome to shoot bricks ~

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.