I have a MVC architecture, and I have the basic views completed. I now need to add the first user tutorial mode into the project. I don’t want to add checks for first user state in all the views that need it, but the only alternative I can think of is to subclass everything and use those subclasses on first open. Is there a standard or widely-used practice for adding support for tutorials, etc. without making a mess of everything?
EDIT: I was unclear in my question.
I’m talking about tutorials that a user encounters when first using the app — in our case we want to add visual effects to direct their attention to key UI elements. I wrote “first user state” to mean we store state about the number of uses on a local machine and use that to determine if display is necessary. Usually I would add some kind of edge case code to the views, say, if User.firstUse() arrowView.show();, but I was wondering if there’s a cleaner way to partition that kind of code from regular code.
6
The main thing here is that you want to decouple the “first view” tutorial content from the rest of your program, so that you can remove that content cleanly from the UI after the user has seen it once. There are a number of design patterns that would let you do that; here are three:
-
decorator: Augment the functionality of an object
foo
by containing it in another objectbar
(the decorator) that has a similar interface and calls through tofoo
for each method.bar
is used in the program in place offoo
, so every time a method in the interface is calledbar
gets a chance to take some action, including modifying the wayfoo
responds to the method. -
delegation: A “helper” object is used to modify the behavior of the delegating object(s). For example, if you’re following MVC, your view object could employ a delegate that inserts the tutorial material. When certain interesting events happen (view appears, user clicks a subview, view disappears, etc.) the view could offer the delegate a chance to respond. Once the user has seen the tutorial you can just skip creating the delegate and the tutorial material won’t show up.
-
observer: Your view would send messages to any registered observer objects at interesting points in the program. Objects using the observer pattern are so loosely coupled that it’s usually difficult for the observer to modify the behavior of the observed object, but that may not be necessary. For example, if you can provide a transparent view that overlays the regular UI, that view could observe what’s happening in the UI and display tutorial content as necessary. When you don’t want the tutorial, don’t create the overlay.
Some of these patterns have potential to help you do more than just provide the tutorial content. If you were to implement my example in observer, for instance, you could use the same mechanism to display diagnostic information instead of tutorial content, so that debugging becomes easier.