デザインのアドバイスを頂きたいです。温度を制御するオーブンがあり、温度に依存する測定を行っています。私は基本的に温度を設定し、いくつかのものを測定し、次に進みます.
もちろん簡略化した 2 つのデザインを思いついたので、以下に示します。最初のものは、コールバック ベースのアプローチを使用します。
class Oven(object):
# ... some methods
def step_temperature(start, stop, num, rate, callback):
temperatures = np.linspace(start, stop, num)
for t in temperatures:
self.temperature = t, rate # sweep to temperature with given rate
self._wait_for_stability() # wait until temperature is reached.
callback(t) # execute the measurement
# Use Case
oven = Oven()
oven.step_temperature(start=20, stop=200, num=10, rate=1, callback=measure_stuff)
2 番目の設計は、発電機ベースの設計です。
class Oven(object):
# ... some methods
def step_temperature(start, stop, num, rate):
temperatures = np.linspace(start, stop, num)
for t in temperatures:
self.temperature = t, rate
self._wait_for_stability()
yield t
# Use Case
oven = Oven()
for t in oven.step_temperature(start=20, stop=200, num=10, rate=1):
measure_stuff(t)
私は 2 番目のデザインの傾向がありますが、あなたの提案に興味があります。もっと良い方法があれば、遠慮なく教えてください。