Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2010 22:45
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 anonymous/702672 to your computer and use it in GitHub Desktop.
Save anonymous/702672 to your computer and use it in GitHub Desktop.
# The Single Responsibility of this method is to edit the canvas
# given a brush and the point where the user interacted.
def editCanvas(canvas, pointer, brush):
# The canvas being read only is an exceptional situation
# that can be handled by the editCanvas method.
# The situation is handled using a guard clause
if canvas.isReadOnly:
return
# This line is a part of the Normal Flow because it is not
# contained within a conditional.
# The behavior of this line belongs to the Main Flow.
# Further, editCanvas has multiple flows it can use to achieve
# it's responsibility. This line expresses the Alternate Flow
# using polymorphism.
brush.apply(canvas, pointer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment