Model-View-Controller and Choosing a Framework

When writing a web application, developers can rely on a DOM manipulation library (like jQuery) and a handful of utility plugins. The problem with this is that it doesn’t take long to get lost in a nested pile of jQuery callbacks and DOM elements without any real structure in place for the application.

Fortunately there are modern frameworks that can assist with bringing structure and organization to projects, improving them, and maintain them easier.

Frameworks for the web is called the Web Application Framework (WAF), a software framework that is designed to support the development of dynamic websites, web applications, web services and web resources. The framework aims to alleviate the overhead associated with common activities performed in web development, such as libraries for database access, customizing frameworks and session management, and code reuse.

Model-View-Controller

Model-View-Controller, or MVC, is a modern framework that provide developers an easy way to organize their codes using variations of a pattern. MVC's software architecture pattern separates the representation of information from the user's interaction with it.

Although first developed for personal computing, MVC has been widely adapted as an architecture for application in the World Wide Web in all major programming languages. Several commercial and non-commercial application frameworks have been created with this pattern. These frameworks vary in their interpretations, mainly in the way that the MVC responsibilities are divided between the client and server.

Application development using frameworks consist of modifying callback procedure behavior and modifying object behavior using inheritance. Many frameworks follow the MVC architectural pattern to separate the data model with business rules from the user interface. This is generally considered a good practice as it modularize codes, promote codes reuse, and allows multiple interfaces to be applied. In web applications, this permits different views to be presented, such as web pages for humans, and web service interfaces for remote applications.

MVC separates the concerns in an application down into three parts:

  • Models - Represent the domain-specific knowledge and data in an application. Models notifies its associated Views and Controllers when there has been a change in its state. This notification allow Views to produce updated output, and the Controllers to change the available set of commands.
  • Views - Typically considered the User-interface in an application. A View requests from the Model the information that it needs to generate an output representation
  • Controllers - Handle the input in an application and Views can be considered as handling the output. When a Controller updates the state of a model, it doesn’t directly tell the View. This is what the observing nature of the View and Model relationship is for.

Other Types of Framework Architectures

Most Model-View-Controller frameworks follow a push-based architecture, or also called action-based. Beside MVC as the most commonly used framework for web application, there are two other types of frameworks that are used often:

Push-based vs. pull-based frameworks

Frameworks that use actions that do the required processing, and then "push" the data to the view layer to render the results. Yii, Django, Ruby on Rails, Struts, Struts2, Symfony, Spring MVC, Stripes, Play and CodeIgniter are grouped into this architecture.

On the other hand the pull-based architecture, or also called component based, are frameworks that start with the view layer that "pulls" the result as needed. JBoss Seam, Lift, Tapestry, JavaServer Faces, and Wicket are examples of pull-based architectures.

Three-tier organization

In three-tier organization frameworks, applications are structured around three physical tiers: client, application, and database (normally RDBMS). The application contains the business logic, running on a server and communicates with the client using HTTP. The client, on web applications is a web browser that runs HTML generated by the application layer.

Selecting a Framework

Selecting a framework is about more than simply a part of decision making to select the perfect one for the target requirements.

  • Capability - Developers should review both the source code of the framework and official list of features to see how well they fit with their requirements. There will be projects that may require modifying or extending the underlying source.
  • Flexibility - Since there are many frameworks available, each has its own pros and cons. By design, any framework is limiting, but place less emphasis on the developer having to figure out how things should work on their own.
  • Proven - It’s not only important to know that a framework works in production, but also being able to look at real world code and be inspired by what can be built with it.
  • Mature - The older a framework is, the more carefully planned it is since its strong communities undergo periods of refactoring and breaking changes. Mature projects also tend to have more detailed documentation available, either as a part of their official or community-driven docs.
  • Documentations - Framework should have a detailed set of documentation which will help guide developers using it. Consulting the official framework documentations to find out what its API supports, how common tasks or components can be created with it, etc.. and what the gotchas worth noting are.
  • Dependencies - Frameworks tend to only list the total filesize of the base library itself, but don’t list the sizes of the librarys dependencies. This can mean the difference between opting for a library that initially looks quite small, but could be relatively large.
  • Communities - Communities have always been a way to judge the progress of a product. The more the communities, the more project contributors are. And the more user that can assist if a developer stumbled upon issues.
  • Experience - to choose or not to choose a specific framework also depends on the developer's skills. One developer may find comfortable using a specific framework while other might not. it’s equally as important to write actual code using the framework to make sure the developer is comfortable with the concepts it enforces.