「rubyの入門」rubyでadapter(継承) patter のサンプル

rubyコード:
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

Ruby

Posted by arkgame