MVC – A Mighty Monolith
Tags: csharp, webdev, beginners, mvc
Published: 2023-03-31 11:16:21

Grandpa, can you please tell us a bedtime story?

MVC! MVC! MVC! MVC! I can still hear the triumphant chants of the mighty monolithic architecture. 

Monolithic?

Do you mean all the code is written in the same application? 

What about the separation of concerns? 

Kids, that’s what makes the MVC so mighty. Separation of concerns is a critical component of the MVC Architecture.

I bet you don’t know what MVC is, however, there is no need to worry your little heads. Grandpa will explain everything. 

MVC stands for Model-View-Controller. 

What? Mama’s new stroller?

No silly rabbits, model-view-controller. 

Say it with me, Model…. (model), View…. (view), Controller…. (controller). 

Oh… model-view-controller. Dad says that's an old way of doing things. 

He says software should be built using a microservice architecture. His favorite is BFF(Backend for Frontends).

Well, dad is…

Grandma said if you can’t say something nice…

I know… I know… don’t say it at all.

Dad is a good guy… he just doesn’t know anything about the mighty monolithic MVC!

OK, it's getting late, let's get back to the story.

First, let's start with the model. 

The model is a representation of the data in your application. 

Grandpa, what’s data?

Let’s say that data is information that your application needs. Sometimes the information is already provided for us and sometimes someone enters the information. Either way, we use the model to represent what that looks like. 

I don’t get it…

Let me turn on the light for a moment. Take a look at your star chart. 

Mom made a chart with all of your toys on it, every time they are returned to their proper places, you receive a star.

Just like the model is a representation of the information or data, the star chart is a representation of your toys.

The model makes it easier to retrieve information from the database, in your case, the star chart makes it easier for you to find the toy you want.

I don’t want this story to get overly technical, so let’s move on to the controller.

I thought the view was next?!?!

You’re right! Let’s talk about the view. This is fairly simple to explain. The view is everything that you can see.

Like the sky?

No silly? Everything that you see on an application. 

What do you like when you go to coolgamesforkids.com?

The graphics are awesome! 

I like the colors!

Well, the colors and graphics are a part of the view. The view encompasses all those things, however, it also includes the layout. 

The view allows us to display the data…

From the model?

That’s right, from the model.

It allows us to show the information from our model.

But grandpa, how why do we need a controller? Can’t everything just work with the model and the view? 

You know what?... 

What?!?! 

I heard a rumor about how your great-great-grandpa wrote entire applications in one file with no separation of concerns.

That sounds crazy!

Yes, it does. That’s why it’s called model-view-controller. Not model-controller, view-controller, or model-view. 

You need all the components to make a great application. 

It’s way past bedtime so let’s start wrapping up this story.

We talked about the model, and we talked about the view. But how do you think we tie everything together?

With the controller!!!

That’s right. Everything comes together with the controller.

The controller is like the bus station for our code, it's where the data from our model meets the view. 

Grandpa?

Yes.

What’s a bus station?

What’s a bus station!

Another time I’ll have to tell you about how I had to take a bus in Phoenix, AZ in the middle of July. 

Anyway…

A bus station is a central hub where all the buses meet. There are bus stations all over the city. A bus station allows everyone to connect with other buses as their travel to their desired destination.

The controller does the same thing in a sense. Each controller action represents a view. In this sense, the view will be the bus. The data representation of the model will be the passengers. 

The controller helps us to ensure that the right data gets passed to the right view. 

What happens if the wrong data is passed to the wrong view?

Well… hopefully someone has tested the application before deployment. 

Development is a continuous process, so you won’t catch everything. 

While it may be embarrassing to display the wrong data in a view, it’s not the end of the world.

Grandpa! You’re the best. When I grow up… I want to build ASP.NET Core applications using the Model-View-Controller pattern.

Me too Grandpa!

That’ll make grandpa very happy! Good night kids.

Goodnight grandpa!