DEV Community

Discussion on: Explain Design Patterns Like I'm Five

Collapse
 
cjbrooks12 profile image
Casey Brooks • Edited

When humanity first started making buildings, they were usually made out of sticks, grasses, mud, etc. This worked well for a long time, it gave people some kind of protection from their environment; helps keep out bugs and predators, gives protection from rain, provides a feeling of general security, etc. In fact, in many places around the world, indigenous peoples still build their houses this way, and that's perfectly OK.

Fast-forward to when larger civilizations started to emerge, and you'll find that the old mud huts and tents just aren't going to work. You've got too many people living in too small an area, and while it may be easy to build or rebuild hut for a single family, it's much more difficult to keep an entire city of huts in good order. And since huts are built right on the ground, a city of huts would grow to cover a very large area, making for an inefficient use of the available area, or limiting the population that could live in a given area. The answer, of course, is to build upward rather than outward, using timbers and large stones to construct many-storied buildings that last a longer time. It may be more difficult to build initially, but the benefits in the long-term are definitely worth it.

And going even further, today's skyscrapers are made out of steel and concrete, not wood and stone, which makes them even stronger and more resilient, able to climb higher and support more people than ever before. While it may have taken thousands of years of engineering technology to get to this point, now that we're here it is really easy to go and build another skyscraper, because all the hard stuff has already been figured out by someone else. Now that we have the patterns figured out for how to build a good skyscraper, we just need to go build it.

And this is the purpose of design patterns, like MVC, MVVM, MVP, Clean/Onion Architecture, and so many others. They are by no-means necessary for small projects, and when working with a small codebase, attempting to follow a design pattern can be quite cumbersome. You probably don't need to build a skyscraper for a village of 20 people, and even a house of stone and timbers may be too much. However, if you are expecting your village (project) to grow significantly, it might be worth it to put a design pattern in place, because it is a whole lot easier to build a skyscraper from a clean foundation than it is having to start with a patch of dirt littered with mud huts. Usually, in this case, it is actually easier to just throw away all the old huts, level the ground as flat as possible, and start over with the intention of strictly following a design pattern.