vendredi 26 juin 2015

How to architect 'State Controller' objects being delegates of shared services

I have a UIViewController that currently conforms to the 'Massive View Controller' anti-pattern. I am trying to break functionality out into 'State Controller' objects that act as Controllers for each state that the ViewController might be in. My question is regarding services that multiple states might need to listen to. For example one state might be 'VideoRecordingState' and it has a reference to a 'FileSystem' object that is owned by the UIViewController. When the recording stops the 'VideoRecordingState' is replaced by a 'VideoReviewState'. Both states are interested in listening to the 'fileWriteCompleted' event from the 'FileSystem', and a file write that was started by one state might complete after it has been replaced by another state. So, does each state become the delegate of the 'service' object and just swaps itself out when the state changes, or does it make more sense for the UIViewController to be the delegate of the service and pass the notification on to the current state? Or is this whole design just plain wrong to begin with?

Aucun commentaire:

Enregistrer un commentaire