Last active
May 30, 2018 18:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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