MVC made easy

When I was first learning MVC I don’t have much to any experience programming for the web. I didn’t even now what the request response cycle was. The most programming experience I have ever had was printing interesting patterns using Java.

At the end of the day MVC is much more of an idea about how and why we should structure a program. For example when we write a web site that has your basic CRUD operations, you don’t want everything living in a single file that requires you to use the find functions to find your method.

So start separating out functionality, and at a very basic level we get a Model, View, and Controller. There for each of these things do something very specific. Most applications at a basic level usually involve:

  • Displaying data
  • Working with data
  • Navigation

The MVC design pattern helps you do those things, in a effect organized way. The direct translation would be:

  • Displaying data -> View : Think -> React, Angular, EJS
  • Working with data -> Model : Think -> Plain old classes (ORMs)
  • Navigation -> Controller : Think -> Express.js, Spring, Django

And there you have it, the MVC pattern explained. Now these direct translation might not be true for every framework out there, but for the most part they are true. You can this design pattern applied in almost every app frame work, form Metoer.js to ASP.Net MVC.

Note ORMs aren’t covered in this post, they require their own post to properly explain.

Hope that helped you guys understand.

OOP Explained

Preface

OOP is a way of thinking / design pattern. It can be understood by way of a number of different analogs. Not all the analogs described here are perfect but it makes some of the concepts easier to understand.

Blueprints:

Blueprints tell people how to make things, from your stove to your car. It has a clearly planned out way making sure everything works the way it is supposed to, and makes sure it satisfies it purpose.

You can think about “Classes” in the same way, expect what it builds is not something material, but an entity in computer. So if you wanted to make a car class you would thing about the things it should do. Such as accelerate, brake, turn on and off, open the door, and etc. Notice how all these things involve a verb , these actions that the car can take can be thought of as the methods in class. And then you have the stats of the care, such as the make, model, owner, and etc. These are all nouns and can be thought of as the variables of the classes.

There for when you instantiate a class, your telling the computer to build that objects using the guide (“Class”)

Collections of things:

People collect a lot of different things, from action figures, to stamps. These things all have common figures. Action figures are usually of a fictional character, are made of plastic, can be moved into different positions, and are usually a certain height .

And classes are the same, they hold variables and methods that come together since they are all kind of related. For example a coin classes could have a variable called “metal type” and a method called “flip”.

Cookie Cutters:

Cookie Cutters let you take cookie dough and make interestingly shaped cookies. Which is same thing as what a class does, except the cookie dough is your computers memory, and the cookie cutter is your class. Every time you instantiate a class,  your take some memory forcing it through the classes and making a object.