Reusability of Control

3

I came across the following sentence using MVC:

  

"(...) The View and Controller objects are specifically written to each type of interface (and technology), and are generally not reusable between interfaces."

     

"(...) View and Controller objects are written specifically for each type of interface (and technology), and in most cases are not reusable between different interfaces."

Is Control reusable or does it depend on language?

Font

    
asked by anonymous 29.09.2016 / 19:24

3 answers

3

Is Control reusable or depends on the language?

Depends on the code. I'll tell you about the term Code reuse , also called software reuse , which is the use of existing software, or software knowledge, to build a new software.


Software Reuse

The term software reuse means you can reuse system parts that you have already developed. In this context fits, specifications, architecture modules and source code. Although reuse is related to increasing levels of quality and productivity, reusing a code is not simple. That's because, you need to create "snippets" that can be reused. For example, a site template with the "Home, About Us, Contact" menus.


Reusability in MVC

The core idea behind MVC is code reuse and concept separation. It seeks to organize the project in a way that facilitates reusability and maintenance, and good frameworks that use the MVC standard will further enhance this capability.

In the Model layer, there are the classes that communicate with the Database, representing this information. The View layer will then display the new Model data to the user. The Controller layer is responsible for managing events and triggering the template classes to make changes to the information.

When using the default, changes are contained in your layers, or affect as few other layers as possible. The MVC flow varies according to the implementation of each framework, however it usually follows the scheme:

  • The user interacts with the interface
  • The controller manages the interface events, invoking an appropriate action
  • The model is notified of the action by changing the state of the model
  • The view is notified of the change and is updated


References:

29.09.2016 / 23:18
1

The Controller is usually dependent on the language / technology used by View and Model , so if you change the way the two communicate with the Controller , will make it difficult to reuse it. I'll try to make it clearer with a simple example:

Let's say we have a web application similar to Twitter or Facebook, where we list posts from one or more people related to a user. And as it goes down the scroll bar of the page, more posts are loaded dynamically.

Let's name our MVC components here:

View

As we are developing a web application, we can say that our View , ie the components with which the user can interact, is our markup (HTML).

Controller

Again, because we are working with a web application, the component that will intermediate our and our Model will be a browser-supported scripting language, most likely Javascript.

Model

Our Model is a service written in any server language, with which we communicate via HTTP. This service is responsible for the business logic of the application. In our case it will return us the posts of people related to the user who is using our application.

Now that we have our application designed and know the responsibilities of the technologies, we see clearly what will happen when the user uses the scroll bar:

  • Our Controller will be activated by the scroll vent event of the browser.
  • Our Controller will then take the information needed to make an HTTP request for our service. (Probably via ajax, which is a feature offered by most browsers to execute HTTP requests without reloading the page.)
  • Our Model will receive the request, apply business logic and return to our Controller .
  • Our Controller will update our View with Model information.

Now imagine that we have to make an application with the same behavior, using the same service ( Model ) only now for Desktop, or Mobile. Which components would we have to change in our current application?

Most desktops or mobiles offer features to use the HTTP protocol, this means that we can communicate with our model from any platform, ie it remains unchanged. But not all of them offer a Javascript interpreter or HTML renderer. So let's have to adapt the View and Controller to the new platforms / technologies.

This is a type of application that does not reuse Controller because the platform with which the user will interact changes.

I hope I have helped.

    
29.09.2016 / 22:14
0

It's hard to reuse Views and Controllers. Generally they are coupled with technology. I will give examples with Microsoft technologies that I use. It's not a very technical answer, but I hope it helps.

Model Reuse

I can create a C # or VB.NET Model that I can use in an ASP.NET MVC, ASP.NET WebForms, WPF, and Windows Forms solution. All I have to do is create this model in a Class Library project. I could use a model made in Delphi for example with DllImport , just as another technology can use this model if I compile for interoperability and this technology is capable of consuming DLLs.

Controller

Now my Controller in ASP.NET MVC will inherit from System.Web.Mvc.Controller . My controller in WPF should be something totally different that knows nothing about 'System.Web. I can not take advantage of the driver.

The Controller takes the intermediate between View and Model . For this, it must use different artifacts to retrieve data from the View: The ASP.NET driver should be able to manage HTTP protocols, POSTS, GETS etc to read View data.

Frameworks

For example if I create a Model in CodeIgniter (PHP), a model that extends CI_Model , I will not be able to use this model in another PHP application without the CodeIgniter installed. I generated here a coupling to the framework. What I mean is that reusing code is not that simple.

    
29.09.2016 / 21:07