Innovation Management and Education Excellence through Vision 2020
Model View Controller – A Comparative .NET Versus Java Analysis Dospinescu Octavian, Alexandru Ioan Cuza University, Iasi, Romania,
[email protected] Donu Bogdan-Andrei, Alexandru Ioan Cuza University, Iasi, Romania,
[email protected]
Abstract In this article we analyzed the Model-View-Controller paradigm (MVC) in detail through two modern technologies (.NET and Java). Starting from MVC's evolution and concepts, we analyzed the defining components of the model and conducted a comparative case study that looked at the following aspects: security degree, total cost, application complexity, runtime, portability, user interface. The results are presented in detail for each platform. After performing the comparative analysis, we identified several future directions for the Model View Controller pattern.
Keywords: Model View Controller, MVC Analysis, future of MVC Introduction - Evolution and Specific Components for Model View Controller The evolution of Model View Controller Technology is constantly evolving, and to be in the top is vital to keep up with the changes. Any company that wants to be efficient must take advantage of new IT solutions to optimize their internal processes. The complexity of applications is rendered by the interface, which changes at an alert pace, with consistent differences compared to previous versions. The graphical interface is intuitive and easy to use even for a simple user, but this is hard to test, and an application typically has more interfaces. Because the user interface changes very often, emphasis has been placed on separating it from the logical component behind and determining the behavior of the application. Over time, there have been many solutions to this problem, but one of the most used and known in web application development is the Model-View-Controller pattern. It was invented by Trygve Reenskaug when he was working at the Xerox Palo Alto Research Center. His first work (Reenskaug 1979)was written in 1978, the original model being called Thing Model View Editor. The pattern was first implemented as a SmallTalk-80 programming language library (Krasner and Pope 1988) and was used to create Graphical User Interface (GUI). The initial significance of the Model View Controller was very different from the meaning of the model today. Below are the two models and the differences between them. In the context of a graphical user interface (first version), Model View Controller was interpreted as follows (Walther 2008): - the Model component: represents the data of an object/object structure in an application; - the View component: a view of the model data, the same model being represented by multiple views. For example, a grade can be written in numerical or lettering; - the Controller component: collects the user input data and modifies the model. For example, when double clicking on a web interface, it changes and displays something else (model data has changed).
4728
Innovation Management and Education Excellence through Vision 2020
Figure 1: The first representation of the MVC pattern (Source: (Walther 2008))
It can be seen from the above figure that the View element is updated through the Model component and not the Controller (between the Controller and the View component is not a link). Instead, the Controller modifies the Model component and, as the View element observes the pattern, pattern, the view is updated. When the pattern changes, an event is triggered, and the changes in Visualization occur in response to the event. In the current version of Model View Controller, there is no longer any relationship between the View and Model component. All communication between visual and persistence is achieved through the Controller.
Figure 2 : The present MVC pattern (Source: (Walther 2008))
The Model View Controller components Model View Controller (MVC) is an architectural software model for deploying user interfaces on computers. He divides a given application into three weakly interconnected parts (model, view, and controller). This is done to separate the internal representations representations of information from the way information is presented to users. The relationships between the components of the MVC pattern are illustrated in the following figure:
4729
Innovation Management and Education Excellence through Vision 2020
Figure 3 : Relationships in the Model View Controller pattern A software solution developed with the MVC architecture has the following mode of operation: 1. The user interacts with the interface (example: click on a radio button); 2. The controller receives this event, validates it and transmits it to the Model element; 3. The Controller also tells the Model that the state must change due to user interaction on the interface (example: That radio-button could indicate the person's type, and after ticking an option (M or F) the BD field is updated); 4. A View interrogates the Model in relation to the current state and the Controller sends it to the View New State. (Example: View updated with old status plus gender confirmation) 5. The interface stays "static" until the next user action. The Model component is the primary element of this architecture and explains the behavior of the application, independent of the user interface. The model encapsulates data and procedures that help in the specific processing of the application. Controllers call these procedures on behalf of the user, and the View component displays the new changes that occur in the interface. The model also provides functions that can access the data that is displayed. The change-propagation mechanism maintains a dependency register within the model, which changes the element in the interface, the View and Controller components are announced. The model is usually both a database and business logic behind the application. A view can be any form of representation of an output, such as graphs, tables or diagrams, and so on. Each view is an update procedure that is enabled by the change-propagation mechanism. When a procedure is called, the View component receives the current Model data and displays it on the screen. The View is the interface of the software solution and transmits to the Controller all the actions that take place. The View component often offers the functionality that allows Controllers to manipulate the display. This is useful for user-initiated operations that do not affect the Model (does not change Model data), such as the scroll (no changes to the database). A web application is usually composed of a set of controls, patterns, and views. The first component can be structured in the form of a main Controller that receives all requests and calls the Controller dealing with a particular case. Its role is to coordinate data between the two classes of objects (Ibrahim 2006), (Sarker and Apu 2014). The controller connects between Model and View, between user actions and the logical part of the application. Depending on the user's needs, the Controller calls various functions specifically defined for the site section in which they are located. This component contains the most code lines as it is the means by which the user interacts with the application. Due to the fact that Model View Controller is
4730
Innovation Management and Education Excellence through Vision 2020
an organizational pattern, not a concrete implementation technique, most modern platforms (.Net, Java, Python, etc.) allow the use of this model by incorporating web frames that help the developer structure application. Complex web solutions can have many code lines, so it's a good idea to structure your application architecture right from the start. There are many techniques available to create a web application, but all of these techniques have some advantages and disadvantages. In this article, we'll focus on Active Server Pages (ASP) and Java Server Pages (JSP), which are two of the most important techniques for implementing the MVC pattern. The Model View Controller pattern is further shown for each platform specified above.
Model View Controller in ASP. Net MVC Active Server Pages (ASP) .Net MVC is a web development framework offered by Microsoft that combines the existing advantages of ASP .NET platform with the strengths of the Model View Controller architecture. ASP .Net supports three major web application development models, namely: through web forms, web pages, and Model View Controller architecture. In order to create web solutions using the .Net MVC framework, we need Visual Studio, which contains a complete set of development tools for any type of application (Freeman, Pro ASP.NET MVC 5 Platform 2014), (Velasco 2017), (Freeman, Understanding Angular and ASP.NET Core MVC 2017). Figure 4 shows how the main components of a web solution (developed using the MVC .Net ASP framework) interact.
Figure 4 : ASP .Net MVC workflow 1. The user attempts to access the web page / resource through a URL (Uniform Resource Locator); 2. The HTTP request reaches the first component of the MVC architecture, this being the routing engine (the routing engine); 3. Based on mapping between URLs and Controllers, the routing engine searches for the corresponding URL controller. If the controller is found, it is invoked; 4. The controller interacts with the model based on the user's HTTP request. If data is received from the user, the model is updated and the controller receives the new "status" of the application; 5. The controller sends to the View component the current status of the application; 6. The controller sends the result received from View to the browser as part of the HTTP response; 7. The browser receives the HTML generated by the application. ASP.NET framework assures the independence of the Model, View and Controller components (separates business logic from UI logic), while providing a weak link between these elements and can communicate.
4731
Innovation Management and Education Excellence through Vision 2020
Model View Controller in Java Web application development in Java can be done with the MVC Spring Web Framework. This framework provides Model View Controller architecture and all the components needed to develop a dynamic web solution. The main elements of a web application developed in Spring are the following (Ahmed 2016): - The model: encapsulates the application data and will generally be composed of POJO (Plain Old Java Objects) classes. By using POJO classes, the code can be simplified, and this leads to better application testing, flexibility, and so forth (Stark 2015). - View: is responsible for rendering data in the HTML format so that the browser can interpret the output (Kruk, et al. 2017); - Controller: is the intermediate between the two elements specified above. The following is how the elements of a web solution developed in Spring communicate.
Figure 5 : Spring MVC workflow (Source: (Spring - MVC Framework 2018))
1. After receiving an HTTP request, DispatcherServlet (also called the Front Controller in some versions of the MVC Spring Frame) communicates with Handler Mapping to establish the Request Controller; 2. The controller picks up the request and calls the methods according to the type of request: GET/POST etc. In turn, these methods will update the Model data and transmit the View Name to the Dispatcher; 3. DispatcherServlet will communicate with ViewResolver (maps a real view of each view name) to get the View View; 4. In the last step, the model is rendered and the output (HTML) required for the browser is generated. Finally, we will realize that using a pattern design, such as Model View Controller, will help us develop a web application much faster. Using this pattern, web solutions will be easy to upgrade (scalable), easy to test and easier to maintain.
ASP.Net MVC versus Spring Web MVC - Comparative Study Obviously, Java and .NET have a different approach to web application development. However, both platforms pursue the same goals and target the same market segment, namely scalable web applications. In the literature there are some studies regarding the performance analysis of applications written using MVP and MVC (Aygun and Kazan 2015). Below is presented how the main elements of Model-View-Controller architecture are implemented in Java and .Net.
4732
Innovation Management and Education Excellence through Vision 2020
For a better understanding of these implementations, we will create a class called "Student" and it will have two attributes: "name" and "last name". The user can set and get the value of these properties through the setters / getters, and besides, he can check using the isValid method if the name / surname is valid J2EE (Java 2 Platform, Enterprise Edition) vs. ASP .Net (Active Server Pages .Net) - Model: In J2EE the model is represented by Java bean classes, and in ASP .Net simple classes with setters and getters. Below is the code for both cases.
Figure 6 : The class “Student” iin Java
Figure 7 : The class “Student” in i .Net
The next main element to be explained is the view. It is built with tags () and represents the most visible component of the application, that is, the interface.
Figure 8: JSP simple form
Figure 9 : ASP.Net simple form
Controller: To create a controller in J2EE, we need a class that inherits the "HttpServlet" class. The controller logic is implemented by a method that takes two instances of the Servlet HTTP class as parameters: a Servlet Request HTTP instance and one Response (Aniche, et al. 2017). To create a controller in ASP.Net we need a class that implements the IHttpHandler and IRequiresSessionState interface. Below is the code for both cases.
4733
Innovation Management and Education Excellence through Vision 2020
Figure 10 : Controller class in n Java
Figure 11 : Controller class in .Net
Table 1 lists the main differences between applications developed using the MVC ASP.Net framework and those developed with the Spring MVC framework. frame Table 1: Applications developed in ASP.Net MVC vs. Applications developed in Spring MVC Features Operating systems running Developing environments
GUI (Graphical user interface) Complexity
Applications developed in MVC ASP.Net They are especially designed for Windows users ASP.Net is only available in the Microsoft Visual Studio development environment Microsoft tools allow us to build more friendly interfaces The framework is very well structured and easy to use
Speed for complex web solutions
Web applications developed with the MVC ASP.Net framework are very fast
Degree of Security
The security level is lower
Total costs
The total costs are lower because the MVC ASP.Net framework includes all the functionalities needed to develop a complex web solution (we no longer need other frames)
4734
Applications developed in Java (Spring MVC) It runs the same on any operating system The Spring MVC Framework is available in several development environments Poor quality web interfaces There are many ways to expand and configure, making the Spring MVC a very complex framework Web applications are moving more slowly than those developed in MVC ASP.Net (one reason being that Java is a multi-platform platform programming language) Spring Security provides features for authorizing all layers in the system Total costs are slightly higher compared to the costs of the other option
Innovation Management and Education Excellence through Vision 2020
.NET and Java have long been on the market and are both modern development platforms. However, when we have to make a decision about the platform we want to use, there are some main aspects can be considered (RishabhSoftware 2017): 1. Complexity of the applications - the general perception is that .Net is easy over Java in terms of solutions that need a richer graphical user interface. On the other hand, Java is over .Net for applications that support a large amount of data or users. 2. Portability - As we have seen in the table above, Java has multi-platform compatibility and gives us the freedom to choose the provider. Organizations choose Java when integrating the application with the operating system is a priority. 3. Employee Software Development Skills - It is very important to take into account the infrastructure and capabilities of today's developers because replacing and developing an infrastructure can greatly increase costs.
Conclusion, Discussion And Future Directions In conclusion, when choosing the programming language in which we want to develop the application, we must take into account both the non-functional or technical requirements (for example, application security, speed etc.) and functional (for example, how the computer system should behave). However, our choice should not be based on a better architecture but should be based on the strengths and weaknesses of the technologies and the extent to which the chosen platform meets our established requirements. MVC is widely used and many web applications are based on the pattern Model View Controller Model View Controller can be found in two forms: - Server side MVC (MVC on back end); - Client MVC (MVC on the front end). The View View Controller on the front end is usually built with a frame, developed in most cases in JavaScript (for example, Angular Js). The Controller component also has a large part of the application's behavior, but it is saved on the station (client) (Harms, Rogowski and Lo Iacono 2017). The main difference between server-side MVC and client-side MVC is given by the way web pages are rendered. In the first case, HTML is always fully loaded when we use the application, contrary to the MVC on the front end where the HTML code is loaded and modified only in the parts where the user acted. In 2017, client-side applications were dominant, especially single-page software solutions - these solutions load once the initial page and then request multiple pieces of data through Ajax calls. The problem with these applications is that as users rotate around the page, they create a lot of Ajax requests on the server, which slows the application (Moldovan 2016). Model View Controller is now the best way to develop server-side applications, but this architectural pattern can not be used on the client side because it does not respect its principles and component independence (the View component is tightly linked by the Controller in this case). Another problem encountered in the developed applications based on the client-side MVC pattern is related to the data stored in the Model component. On the one hand, we have data such as users and products, which are the status of the application, and on the other hand, we also need to store the status of the interface through elements such as showTab or selectedValue. Similar to the problem encountered in the Controller, the Model component violates the principle of unique responsibility because there is no separate way to manage the status of the application and the state of the interface. Recently, a number of new frameworks have been introduced that promote the unidirectional data flow concept and solve the problems encountered in the client-side MVC pattern. In short, the new architecture attempts to make predictable changes to the status of the application by imposing certain restrictions on how and when updates can take place. The most notable architecture is Flux and the
4735
Innovation Management and Education Excellence through Vision 2020
most notable framework is React (Simkhada 2017). For now, there are few software developers who have adopted this method, but as they begin to uncover the benefits of unidirectional architectures, many will head to that direction. Flux is the application architecture that Facebook uses to build web client software solutions. It solves the problems encountered in the Model View Controller pattern and respects the principle of unique responsibility using a one-way data stream (Flux in depth overview 2015). Given the above-mentioned arguments, it is expected that in the near future we will no longer use the MVC classic architecture to develop front end applications, but only back end applications (based on the server). Front end (client) software solutions will be developed with the new Flux architectural pattern. Every day, more and more software developers begin to see the benefits of unidirectional components and architectures, with the emphasis on building tools and better libraries in the future.
References Ahmed, Mustafa. 2016. "Implementation of Course Scoring System Based on Spring MVC and Hibernate." Culminating Projects in Computer Science and Information Technology 13. http://repository.stcloudstate.edu/csit_etds/13. Aniche, Maurício, Gabriele Bavota, Christoph Treude, Marco Aurélio Gerosa, and Arie van Deursen. 2017. "Code smells for Model-View-Controller architectures." Empirical Software Engineering 1-37. doi:https://doi.org/10.1007/s10664-017-9540-2. Aygun, Coskun, and Emre Kazan. 2015. "The Performance Analysis of Applications Written Using MVP and MVC." INTERNATIONAL JOURNAL OF SCIENTIFIC RESEARCH IN INFORMATION SYSTEMS AND ENGINEERING 1 (2). http://ijsrise.com/index.php/IJSRISE/article/view/33. 2015. Flux in depth overview. Facebook Inc. Accessed 2018. https://facebook.github.io/flux/docs/indepth-overview.html#content. Freeman, A. 2014. Pro ASP.NET MVC doi:https://doi.org/10.1007/978-1-4302-6542-9_1.
5
Platform.
Apress,
Berkeley,
CA.
Freeman, A. 2017. "Understanding Angular and ASP.NET Core MVC." In Essential Angular for ASP.NET Core MVC. Apress, Berkeley, CA. doi:https://doi.org/10.1007/978-1-4842-2916-3_1. Harms, Holger, Collin Rogowski, and Luigi Lo Iacono. 2017. "Guidelines for adopting frontend architectures and patterns in microservices-based systems." Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering. 902-907. doi:10.1145/3106237.3117775. Ibrahim, N. 2006. "Applying a Model/View/Controller Pattern in J2EE Platform Using Struts Framework." Jurnal Sistem Informasi 1 (2): 129-147. http://jutisi.maranatha.edu/index.php/jusi/article/viewFile/205/203. Krasner, Glenn, and Stephen Pope. 1988. "A Description of the Model-View-Controller User." Journal of object oriented programming (ParcPlace Systems). https://www.researchgate.net/profile/Stephen_Pope/publication/248825145_A_cookbook_for_using_ the_model_-_view_controller_user_interface_paradigm_in_Smalltalk__80/links/5436c5f30cf2643ab9888926/A-cookbook-for-using-the-model-view-controller-userinterface. Kruk, G., O. Alves, L. Molinari, and E. Roux. 2017. "BEST PRACTICES FOR EFFICIENT DEVELOPMENT OF JAVAFX." 16th Int. Conf. on Accelerator and Large Experimental Control Systems. Barcelona, Spain: JACoW Publishing. 1078-1083. Accessed 2018. doi:doi:10.18429/JACoW-ICALEPCS2017-THAPL02.
4736
Innovation Management and Education Excellence through Vision 2020
Moldovan, A. 2016. Is Model-View-Controller dead on the front end? freeCodeCamp. https://medium.freecodecamp.org/is-mvc-dead-for-the-frontend-35b4d1fe39ec. Reenskaug, Trygve. 1979. "The original MVC http://heim.ifi.uio.no/~trygver/2007/MVC_Originals.pdf.
reports."
Accessed
2018.
RishabhSoftware. 2017. Java vs .NET: Core Features and Differences Between the Two. Rishab Software. Accessed 2018. https://www.rishabhsoft.com/blog/dot-net-vs-java. Sarker, I.H., and K. Apu. 2014. "Mvc architecture driven design and implementation of java framework for developing desktop application." International Journal of Hybrid Information Technology 7 (5): 317-322. doi:http://dx.doi.org/10.14257/ijhit.2014.7.5.29. Simkhada, Kumar. 2017. Transitioning Angular 2 User Interface (UI) into React. Helsinki. Accessed 2018. https://www.theseus.fi/bitstream/handle/10024/124681/thesis_final.pdf?sequence=1. 2018. Spring MVC https://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm.
Framework.
Stark, S.M. 2015. Providing a POJO-based microcontainer for an application server. USA Patent US9009699B2. Accessed 2018. https://patents.google.com/patent/US9009699B2/en. Velasco, Ryan. 2017. ASP.NET Multitenant Applications: For Starters. USA: CreateSpace Independent Publishing Platform. Walther, Stephen. 2008. "The Evolution of MVC." http://stephenwalther.com/archive/2008/08/24/the-evolution-of-mvc.
4737
Accessed
2018.
Proceedings of the 31 International Business Information Management Association Conference st
(IBIMA) 25-26 April 2018 Milan, Italy
ISBN: 978-0-9998551-0-2
Innovation Management and Education Excellence through Vision 2020
Editor
Khalid S. Soliman
International Business Information Management Association (IBIMA)
Copyright 2018