Life is a highway … or a roller coaster … or is it like a box of chocolates? In software development, metaphors can be very useful when trying to understand a new concept. I have been reading the excellent Code Complete 2 by Steve McConnell. In Chapter 2, he states the following:
“A software metaphor is more like a searchlight than a road map. It doesn’t tell you where to find the answer; it tells you how to look for it. ”
I have had my first experience of the Model-View-Controller (MVC) recently and, having worked mainly with Windows Forms, I have found the shift in thinking to be challenging. Despite an excellent lesson from our in-house teacher, Andy, I found that MVC wasn’t as straight-forward as I’d hoped. Knowing the value of a good metaphor, I found a great post DEV.to that put MVC in terms that I might understand. “Explain MVC like I’m Five“. The title spoke to me.
I found a series of great comments in this thread, but some jumped out at me more than others. This lead me to search online for other metaphors for MVC – the simpler the better. Below, I have shared some of my favourites.
- Imagine a shop with three workers. One is responsible for taking the customers’ requests, one is responsible for getting the item the customer wants, and the third one wraps the item in nice packaging and presents it to the customer.
- You walk in a McDonald and you order at the big interactive touchscreen. You place your order at the screen – this is the View. Your order is passed on to the worker who will go and fetch your order – this is the Controller. Finally, the type of order that you have placed is the responsibility of the Model.
- Mark understands the toys in the toy box.
Vicky knows how to set out toys for certain games.
Charlie tells Mark to get the toys for a certain game and tells Vicky to set them out. Vicky tells Charlie what new game the user would like to do.
This continues for the entirety of play time.
As I gain greater understanding of MVC, I hope that I will be able to create my own metaphor that works best for me.