When adhering to Liskov Substitution Principle (LSP) can a child class implement additional interface?

前端 未结 2 2096
清酒与你
清酒与你 2021-02-11 02:22

Consider this ruby example

class Animal
  def walk
     # In our universe all animals walk, even whales
     puts \"walking\"
  end

  def run
    # Implementing         


        
2条回答
  •  攒了一身酷
    2021-02-11 03:00

    LSP says you can drop in any implementation of the base type/interface, and it should continue to work. So no reason why it should violate that, although it raises interesting questions about why you need to implement that additional interface in one implementation and not others. Are you following the single responsibility principle?

提交回复
热议问题