Refactoring InstructionsController

Since we are going to an event-listener model, the controller no longer needs to directly know which UI elements to update each time the user steps through the instructions data. Delete the declarations for stepText, titleText and bodyText.

Then we can replace CurrentInstructionUpdate() with the following, much simpler, code that invokes our event by calling OnInstructionUpdate.Invoke():

    private void CurrentInstructionUpdate() { 
        InstructionStep step = currentInstructionModel.GetInstructionStep(currentStep); 
        OnInstructionUpdate.Invoke(step); 
    } 

Now, whenever the controller wants to update the screen, it invokes our OnInstructionUpdate event.

Get Augmented Reality for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.