Hat Is MVC
Hat Is MVC
Author: Jeremy
Morgan
What is MVC?
MVC is not really a package or a tangible object but more of an idea or
methodology. Microsoft has a software package for ASP.Net
called Microsoft MVC but its not really a product as much as an
implementation of the pattern. There are other projects out there similar
to this, but you can build a Model, View and Controller in any language.
Its simply a way of building software that has many benefits, heres a
rough idea of how it works:
First the visitor opens a web browser, and a command is sent to the
controller to show a web page. The controller then contacts the model,
which pulls raw data from the database and passes it back to the
controller. The controller then passes it to the view which formats the
data and mixes it with html to create a web page you can view.
Advantages of MVC
MVC frameworks do not offer any additional performance or features to
your application, they exist primarily to help the programmer(s).
Separation of Concerns: - This is a tenet of good design and
encapsulates your functions and creates a defined interface. For
example someone working on a model only has to worry about
interfacing with a database and getting the right information, but
doesnt have to worry about browser compatibility at the same time.
Code Reuse: - Because of the separation of concerns with MVC you can
reuse your code easily. If you have a great view object that displays
pages well on a phone for example, you can reuse that same code easily
as a view in another application.
Decoupling: - Another tenet of good design, keeping your software
decoupled means easier changes down the road. For instance if youre
changing database servers from one vendor to another do you want to
rewrite or modify your model, or the whole piece of software? With a well
implemented MVC framework you can do it in a fraction of the time.
Testability - While having your software decoupled and separated is
good for programming, its great for testing. You can take a section of
code and easily run various tests on specific parts of the program as you
go along and those tests can be very focused. Are you looking for data
integrity? Expected display? When functions are clearly grouped testing
becomes far simpler and more organized.
Disadvantages of MVC
So if MVC is the greatest thing since sliced bread then why isnt
everyone doing it all the time? Its a mistake to think MVC is a magic
bullet that will cure all your software problems.
Summary
I hope Ive given you a general idea of what MVC is and you may even
be considering it for your next project. Generally the following projects
are best suited for MVC frameworks or design: