ruby 接口隔离失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 接口隔离失败相关的知识,希望对你有一定的参考价值。

# Interface segregation principle violation
class CoffeeMachineInterface
  def select_drink_type
      # select drink type logic
  end

  def select_portion
     # select portion logic
  end

  def select_sugar_amount
     # select sugar logic
  end

  def brew_coffee
     # brew coffee logic
  end

  def clean_coffee_machine
    # clean coffee machine logic
  end

  def fill_coffee_beans
    # fill coffee beans logic
  end

  def fill_water_supply
    # fill water logic
  end

  def fill_sugar_supply
    # fill sugar logic
  end
end

# Class Person, depends on methods it does not use
# e.g fill_sugar_supply, fill_water_supply
class Person
  def initialize
    @coffee_machine = CoffeeMachineInterface.new
  end

  def make_coffee
    @coffee_machine.select_drink_type
    @coffee_machine.select_portion
    @coffee_machine.select_sugar_amount
    @coffee_machine.brew_coffee
  end
end

# Class Staff, depends on methods it does not use
# e.g select_drink_type, select_portion
class Staff
  def initialize
    @coffee_machine = CoffeeMachineInterface.new
  end

  def serv
    @coffee_machine.clean_coffee_machine
    @coffee_machine.fill_coffee_beans
    @coffee_machine.fill_water_supply
    @coffee_machine.fill_sugar_supply
  end
end

以上是关于ruby 接口隔离失败的主要内容,如果未能解决你的问题,请参考以下文章

如何隔离 Ruby 中的方法 - 多处理问题

在 Ruby/Rails 中隔离数据访问层的最佳实践

Spring Cloud调用接口过程

当失败的测试被转移到隔离区时,防止 Bamboo 工作失败

设计模式六大原则(四)----接口隔离原则

Soul网关Hystrix插件相关知识点扫盲