Personal PHP coding style of Service Layer Interface

Scenario Description:

A mall site, order merchandise table + table + table + user information product image

Each write out the interface,

Too general a bad use == == == pass multiple parameters to understand in order to use N == better to write their own

== single function transfer an ID to return a bunch of nice things to me == == == everywhere write interface multiplexing rate == add SQL field to change the place of N

So, after I decided to write this:

Get a single message, do not join the SQL table into a big-time to check out and then enumerate each state to write it again, you can get product information order information + + user information, a small SQL can prevent clogging provided here == each interface getById

Get a list, it is impossible to remove the order lists foreach obtain product information and user information, available directly join table

Example code:

<? PHP 

// the PHP interface style 

// Product 
class Good {
     / * * 
     * commodity information acquired 
     * 
     * @param [int] good_id '. 1' 
     * @return [ARR] Array ( 'retcode' => 'response code' , 'data' => 'data, typically an array of', 'msg' => 'message, typically string') 
     * @author the Author 
     * @Since years. 1, 2015 dated 12 is Day 
     * /  
    public function getGoodInfo ($ good_id) {
         // check parameters
         // various enumeration mapping transformation
         // fixed format Back 
    } 

    / * * 
     * commodity information acquired plurality 
     * 
     * @param [int] good_ids 'l, 2,3'
     * @Return [arr] array ( ' retcode' => ' response code', 'data' => 'data, typically an array of', 'msg' => 'message, typically string') 
     * @author the Author 
     * dated 12 is @since 2015 years. 1 Day 
     * /  
    public function getGoodList ($ good_ids) {
         // check parameters
         // various enumeration mapping transformation
         // fixed format return 
    } 
}

 

Guess you like

Origin www.cnblogs.com/xuweiqiang/p/11280087.html
Recommended