phper进阶之路--- Go 接口编程 组合

1、接口的组合

    (1)接口之间可以嵌套接口,使某个接口同时具备多个接口的功能,类结构体只需要实现接口的方法就可以了

   (2)接口的组合:

            A、type A interface {  Post(url)string ;}

                   type B interface  {  Get (url) string ;}

        超级接口: type   C  interface {  A  ; B ; Put(url) ; }    //    其中 Put()方法是接口C独有的

       等价于 : type C  interface  {   Post(url)string ; Get (url) string ;  Put(url) ; }    //接口A、B类似php中的trait类

(3)类结构体:

        type   Down struct{      a int  ;  contents   string ;       }

    func( a Down)Post(url)string {   return  “。。。。”; }

    func( a Down)Get(url)string {   return  “。。。。”; }

    func( a Down)Put(url){   return  ; }

(4)统一方法:

func   GetFileDown(re  C){  re.Post(...);   re.Get(...) ; re.Put(url); }


(5)常用的系统接口:

phper进阶之路--- Go 接口编程 组合

    

phper进阶之路--- Go 接口编程 组合