Tuesday 2 February 2016

MVC


MVC

MVC is a powerful software developing design pattern.


MVC Architecture is a three tier architecture, something like PL-BAL-DAL, which is linear but has three layers. Unlike PLBALDAL, MVC is triangular. The path which connects the different separation of concerns is triangular in MVC. We have to understand what does separation of concern means by the way, before going any further.

Nowadays, the software has to have a lot many things, there are basically three things, the part which will be facing the user of the software, for example, dash board. There are so many ways one can develop this part. The page we get after typing www.google.com in address bar is the presentation logic.

The second part is the business logic which will be operated by the presentation logic, business logic is the actual part of processing, there are thousand of languages which have been invented to code just this part, for example, c#, c, c++ and many more. They can code mathematics, decision making, looping, calling a function and converting some code to machine level etcetera. Whatever happens between pressing the Google's search and search result is the business logic.

And the third part is database access layer, which persists the data so generated by the business logic by interacting with presentation logic. Our gmail account details are memorized by gmail. This phenomenon is the Data access part. 

So, any software not only google, if follows such a pattern then it is said to have followed a three tier PLBALDAL pattern. Each of these three things are termed as concerns, when we try to develop any software.

Earlier we used to code each and every part in just single place and by single language. But as the software users are increasing in numbers, the data is increasing exponentially. We just have to visit facebook.com , there we could see the flood of data of every genre. When things get huge, it is better to divide it. When problem is big, it is advisable to divide it into smaller parts. So, separation of concern is basically division of similar looking logic into one whole logic. The look and feel is divided into PL, the working area is BAL and the memorizing the outcome to DAL  as because it was becoming huge, very huge like almost uncountable lines of code.

MVC is invented to divide further the PL into three parts, namely MODEL, VIEW and CONTROLLER.

We get confuse, it is not like DAL and BAL, which would have data and business logic, the Model and View are only concerned about the Presentation logic.
It is the separation of concerns which would divide the colour and design from a painting. The person who would be responsible in uniting colour and design would be doing it dynamically, and that person is known as Controller.
View would only be holding the designs and the colour would be stored in model and Controller will decide which design has to be painted with which colour. 
It might be possible that a particular design would not look good in a colour, the situation would get worse, when we cannot change the colour or suppose we have purchased the design which has come in red colour factory fitted, so in this case we would have to order new design painted in the colour we want. This is tightly coupled or tightly depended on each other.
 In software development, there is no such relief than a chunk of code is heavily loosely coupled. Think about the Google doodle, they update it on every occasion,try to imagine, if they would have glued some doodle then what problems they would have to face while putting some other in its place. It is loosely coupled.
Similarly, when we want the things to behave as loosely coupled in Presentation logic, we implement the MVC design pattern.
Lets understand in terms of website development.
The HTML content of the web page is the View but the data held by the html elements would be not glued directly into them.It would be stored in Model.

During the run time, based on what page and what data, a user has requested, the controller would visualize and glue it immediately onto a view and hand it over to the user in the form of a webpage.
Unlike previous versions[PLBALPAL], where the data of the presentation logic has to be tightly coupled with the data being given to BL by DAL to PL.

MVC is an attempt to decouple the Presentation from its logic.The request is taken by the Controller. The View and Model would never know each other in MVC directly. They don't get into conversations and sharing things. It is the duty of Controller to map Model's contents to a Veiw's content into one Presentation and this is the only time when they come to know about each other.
In  desktop application apps also like the software developed using Windows Presentation Foundation[WPF] which follows MVVM pattern which is almost same like MVC. The Controller would be the first person to get connected, it could literally be a controller or some part which behaves like a controller. In MVVM the VM part behaves like a controller. It attaches the data to view, hence, VM stands for View Model.

Therefore, MVC is invented get a better hold on the presenation part of a software which also makes testing more easier to do. Testing of the Presentation Logic is tedious task, indeed but through MVC is easier than ever.

Thanks and keep harworking!!

Ashumeet Mitter

No comments:

Post a Comment