We don't really change the resource that is passed in. Because Python is pass by object reference, doing a re-assignment operation does not actually change the resource i.e. resource = 'unlocked' does not really work. Furthermore, the resource variable, with which the unlock function is called, is a string; strings are immutable; thus, we need to pass in a mutable data type as the resource to be able to demonstrate the resource's "lock state" changing. While we could have used a simple "box" tactic i.e. resource = ['locked'], this seemed to distract from the goal of the example. Consequently, it seemed using a small class might be clearer without detracting from the example's value.
By doing:
We don't really change the
resource
that is passed in. Because Python is pass by object reference, doing a re-assignment operation does not actually change theresource
i.e.resource = 'unlocked'
does not really work. Furthermore, theresource
variable, with which theunlock
function is called, is a string; strings are immutable; thus, we need to pass in a mutable data type as theresource
to be able to demonstrate the resource's "lock state" changing. While we could have used a simple "box" tactic i.e.resource = ['locked']
, this seemed to distract from the goal of the example. Consequently, it seemed using a small class might be clearer without detracting from the example's value.