Prebound Method Pattern
Prebound method pattern is a native to python language. In this pattern, we assign bounded methods of class instances to names in module namespace. For example, random
library has methods randint
etc, these methods are bounded method of random.Random
class instance.
class Colorcycle:
def __init__(self):
self.step = 0
self.colors = ["red", "yellow", "green"]
def next_color(self):
color = self.colors[self.step % len(self.colors)]
self.step += 1
return color
_instance = Colorcycle()
next_color = _instance.next_color
Now, next_color
can be used.