I have a class, CameraInterface, with two properties:
recording(a boolean)recording_quality(an enumeration with three possible values)
The user can push hardware buttons (this is a Raspberry Pi project) to select the recording_quality, but if the camera is already recording, the hardware will blink/buzz/otherwise indicate that you can’t change the recording_quality while you are recording.
I would like the CameraInterface object to enforce this requirement. I don’t want future me to be able to forget this requirement, and accidentally try setting the recording_quality without first making sure that recording is False. What is the most Pythonic way to do this?
I’m most familiar with Objective-C, where I might try making the property externally readonly, and then doing something like this:
- (void)setQuality:(Quality)quality
successHandler:(void (^)(void))successHandler
failureHandler:(void (^)(void))failureHandler
{
if ( self.recording ) {
if ( failureHandler ) {
failureHandler();
}
}
else {
self.quality = quality; // internally writable
if ( successHandler ) {
successHandler();
}
}
}
Aucun commentaire:
Enregistrer un commentaire