Ruby 设计模式适配器

案例:

class FormatAdapter
    def format
        puts "build format"
    end
end

class BuildFormat
    attr_accessor some_adapter

    def initialize(some_adapter)
        @some_adapter = some_adapter.new            
    end

    def build
        @some_adapter.format
    end
end

# 使用
bf = BuildFormat.new FormatAdapter
bf.build

Comments

Copyright © 2017 kaka