Skip to content

Instantly share code, notes, and snippets.

@Mardiniii
Last active May 30, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mardiniii/6c696bb1810f35b0f425fc523f939ce1 to your computer and use it in GitHub Desktop.
Save Mardiniii/6c696bb1810f35b0f425fc523f939ce1 to your computer and use it in GitHub Desktop.
Interface segregation principle: A client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.
# Violates ISP
class Airplane
def load_luggage
end
def load_fuel
end
def take_off
end
def land
end
end
class Controller
def run_checklist
@airplane.load_luggage
@airplane.load_fuel
end
def assign_turn
end
end
class Pilot
def flight
@airplane.take_off
end
def end_flight
@airplane.land
end
end
# Enforces ISP
class Airplane
def take_off
end
def land
end
end
class AirplaneDispatcher
def load_luggage
end
def load_fuel
end
end
class Controller
def run_checklist
@airplane_dispatcher.load_luggage
@airplane_dispatcher.load_fuel
end
def assign_turn
end
end
class Pilot
def flight
@airplane.take_off
end
def end_flight
@airplane.land
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment