visitor pattern look at the generic implementation of the visitor pattern and get feel for the code we will dig into the details after this code snippet import abc class visitable(object)def accept(selfvisitor)visitor visit(selfclass compositevisitable(visitable)def __init__(selfiterable)self iterable iterable def accept(selfvisitor)for element in self iterableelement accept(visitorvisitor visit(selfclass abstractvisitor(object)__metaclass__ abc abcmeta @abc abstractmethod def visit(selfelement)raise notimplementederror(" visitor needs to define visit method"class concretevisitable(visitable)def __init__(self)pass class concretevisitor(abstractvisitor)def visit(selfelement)pass we can now return to the example of our friends who are sharing house let' abstract the setting up of the system for each of them using the visitor pattern we will do this by creating visitor for each of the three potential configurations of people inside the houseand then we check who is home before visiting each device and setting it accordingly