def generate_children(count, parent, life_min, life_max):
"""We are using a generator to randomly seed a sequence of specifications for the
factory. While this is not strictly part of the Factory Pattern, it can be useful
for testing the factory or for generating objects based on some pre-defined algorithm.
It is perfectly acceptable to implement factories without generators (depends on your
specific use-case)."""
types = parent.__subclasses__()
for i in range(count):
yield {
"class_name": random.choice(types).__name__,
"lifespan": random.randint(life_min, life_max)
}
评论列表
文章目录