4 ms·
I build most of my classes that way in python. class Motor: def __init__(self): self.max_speed = 10.0 self.clockwise = True
by atoav 4y ago
I build most of my classes that way in python.
class Motor:
def __init__(self):
self.max_speed = 10.0
self.clockwise = True
self.controller = Controller()
def set_max_speed(self, max_speed: float=10.0) -> 'Self':
self.max_speed = max(0.0, max_speed)
return self
def start(self) -> 'Self':
self.controller.start()
return self
etc..
Then you can use it as follows:
motor = Motor().set_max_speed(5.0).start()
There is nothing stopping you from building iterators that work the same way