Ruby适配器模式

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

class Connection
   def request
     raise "Abstract method"
  end
 end

 class MysqlAdapter < Connection
   attr_accessor :connection

   def initialize
     @connection = MysqlConnection.new
  end

  def request
    @connection.request
   end
 end

 class MysqlConnection
  def initialize
  end

   def request
     puts '请求连接 Mysql 数据库'
   end
 end

 mysql_adapter = MysqlAdapter.new
 mysql_adapter.request