- 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
- #该片段来自于http://www.codesnippet.cn/detail/180420132868.html
来源: http://www.codesnippet.cn/detail/180420132868.html