Smart Computing Review, vol. 4, no. 4, August 2014
256
Smart Computing Review
JMVC: A Java Framework for Rapidly Developing Desktop Application Software Based on MVC Iqbal H. Sarker Dept. of Computer Science & Engineering, Chittagong University of Engineering & Technology / Chittagong4349, Bangladesh / Email:
[email protected] * Corresponding Author: Iqbal H. Sarker
Received May 17, 2014; Revised July 13, 2014; Accepted July 19, 2014; Published August 31, 2014 Abstract: Java is one of the leading software development languages. However, the development model of existing Java organizes without structure, mixing the programming code for data access, the processes of business logic, and the graphical user interface layer together. This disorganization creates many problems for software developers, and prevents Java from meeting todays’ requirements for rapid application software development. A model-view-controller framework is a tool for facilitating the rapid development of software in a concurrent software development environment. In this paper, we propose a Java-based model-view-controller framework that we dub JMVC for developing desktop-based applications that can separate the data, view, and controller of the software to enhance the efficiency, reliability, maintainability, and scalability of application software. Keywords: Java, framework, Java-based model-view-controller, architecture pattern, software engineering
Introduction
W
ith the development of information technology (IT), more and more people are dedicated to the software engineering industry. In general, application software contains three major modules, which are the interface, business logic, and data. In traditional applications, the connections among these were very close, so in the early days of software development, developers had to write all the code for the production of any application. Now, the emergence of the idea of a model-view-controller (MVC) framework saves developers from having to start from scratch to some extent. DOI: 10.6029/smartcr.2014.04.002
Smart Computing Review, vol. 4, no. 4, August 2014
257
Using an MPC framework will effectively avoid duplicate code, lower development time and money investment, and improve the quality of software. An MVC framework separates the application input, business logic, and output [6]. Code reuse is one of the most common forms of object-oriented programming utility. Code reuse technology makes software development simpler and more efficient. However, it is not simple enough to copy the existing code and modify it. Based on the overall analysis of user needs and reusability considerations for specific functional modules, the code that can be reused during the software development can be put into a separate file in a shared directory for other programs to call. When developing software, the internal modules should be reused as much as possible. Code reuse can not only greatly accelerate the speed of development and reduce development cost, but also can improve the quality of the system by facilitating finding and fixing problems during testing. Code reuse is also what the vast majority of developers expect, since it is a major goal of object-oriented programming. In this paper, we demonstrate a Java-based model-view-controller framework (JMVC) for rapidly developing desktop-based applications. The rest of the paper is organized as follows. Section 2 mentions the motivation for this framework. Section 3 provides a brief description of previous work related to MVCs and frameworks. Section 4 introduces an overview of MVC components. Section 5 describes our approach and finally, Section 6 concludes this paper.
Motivation The primary purpose of an MVC is to decouple the model subsystem from the views so that each can change independently. The controller subsystem provides insulation between the model and the views. The important benefits necessary to develop a framework based on MVC are:
To group objects into separate model, view, and controller subsystems and decouple those subsystems from each other within an application. By decoupling the subsystems, the model and views can each change without impacting the other subsystems, making long term-software maintenance and enhancement more productive.
To enable multiple views of the same model and support the easy addition, removal, and change of the views.
To promote reuse of both models and views. A model can be reused with many views, and just as importantly, a view can often be reused with different models.
To simplify simultaneous development of models and views by different programmers or different teams of programmers.
Related Work A significant number of MVC techniques and software development frameworks have been implemented in recent years in the software engineering area in order to reuse code and create efficient application development environments. Wei Cui et al. [1] proposed a development framework for PHP based on the MVC design model, which ensures an effective separation of data access, logic processing, and user interface. Thus, it could promote the efficiency and quality of PHP development. However, our concern is desktop software development based on Java. Abhinandan Jain et al. [4] proposed a framework for rapid software development named YAM. This framework provides solutions for thorny development challenges associated with software reuse, managing multiple software configurations, developing software product lines, and even multiple platform development and build management. The YAM framework integrates concepts spanning software organization, build management, release management, and software reuse to provide nimble development processes for managing complex software development. However, they do not consider the MVC technique of separating the presentation layer and business logic of the software. In [5], the authors present a practical management framework for commercial software development with OSS. In the framework, authors define a development process including activities, instructions, and artifacts to use OSS. We also present practices on providing infrastructure and organizational support as well as defining an educational curriculum. However, they don’t consider the MVC technique. In this regard, we propose our JVMC framework to incorporate the MVC technique in a Java-based environment.
Overview of MVC Components MVC is a software architectural pattern in software engineering. It has three components, which are called the model, view, and controller. By dividing the application into model, view, and controller we can, therefore, separate the presentation from the business logic. Decoupling the business logic from the user interface permits independent development, testing,
258
Sarker: JMVC: A Java Framework for Rapidly Developing Desktop Application Software Based on MVC
and maintenance of each. This practice is usually called the separation of concerns. Figure 1 shows the relationship among the components of the MVC architecture.
Figure 1. MVC components and their relationships In an MVC framework, the view and controller belongs to the user interface. In the beginning, a user sends a request to a controller through a graphical user interface (GUI). Then the controller accesses model gives the data according to the user’s request. After that, the model returns the data to the controller, and controller presents the data via the specified view. Finally, a user can see what they want on the screen. The model corresponds to the Business Logic Layer and Data Access Layer. In the Business Logic Layer, we define business entity objects where the business logic is completed. In the Data Access Layer, we use an Entity Data model and related components to implement communication between original data and the Business Logic Layer. We also use a database to store the data and provide an original data source in our system. i.
Model: The model subsystem is composed of the objects that provide the unique capabilities and information storage for an application. Models contain all of the rules for processing application data. The model is the key subsystem that makes an application valuable. It is critically important that the model subsystem is able to stand alone, without dependencies on either the view or controller subsystems. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. The model is not aware of the presentation data and how that data will be displayed.
ii.
View: The view subsystem presents information gathered from the model in a way that users can interact with the information. The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain and render the content. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the view to maintain consistency in its presentation when the model changes. The key to understanding views is to recognize that there is always a multitude of views. For example, there may be a graphical user interface view, a printed report view, a command line view, a Web-based view, and a scripting language view that all interact with the same model.
iii.
Controller: The purpose of the controller is to decouple the model from the views. User interaction with a view results in requests made to the controller subsystem, which in turn may request changes to information in the model. The controller also handles data translation and formatting for presentation to a user. Whenever a user sends a request for something, it always goes through the controller. In an enterprise web application, they appear as GET and POSTHTTP requests, whereas in a stand-alone GUI client, user interactions could be button clicks or menu selections. The controller is responsible for intercepting the requests from view and passing it to the model for appropriate action. After action has been taken on the data, the controller is responsible for directing the appropriate view to the user. Depending on the context, a controller may also select a new view. In GUIs, the views and controllers often work very closely together.
Our Approach – Framework Overview
Smart Computing Review, vol. 4, no. 4, August 2014
259
In this section, we briefly explain the architecture and operation of our proposed framework. JMVC is a three-tier application framework that is organized into three major parts. The three parts are:
User
MVC components
Database
The first tier consists of only the user. The user can send a request and get a response by the “view” components of the middle tier. Second, the middle tier consists of three familiar components named model, view, and controller. These components can communicate and process data for each other. Finally, the third tier contains only the database, where data is stored permanently. Figure 2 illustrates how data flows through the system.
Tier-1
Middle-Tier
Select view
(Controller) Request processing Call model in response to user requests Select view to display response results
Tier-3
Business logic
User request
User
(View) Provide GUI Input user data to the controller Response generation Display user request
(Model) Handle Business logic Data manipulation Inform view business status to update DBMS connectivity
Database
Figure 2. JMVC architecture The operations are described in the following steps: i.
User input is accepted by the component view through the GUI. In a stand-alone GUI client, user interactions could be button clicks or menu selections.
ii.
The controller delegates requests to an appropriate handler. The controller is the means by which the user interacts with the application. The controller is responsible for the input to the model. A pure GUI controller accepts input from the user and instructs the model and viewport to perform an action based on that input. If an invalid input is sent to the controller from the view, the model informs the controller to direct the view that the error occurred and to tell it to try again.
iii.
The controller adapts the request to the model. The model represents, or encapsulates, an application's business logic or state. It captures not only the state of a process or system, but also how the system works. It notifies any observer when any of the data has changed. The model would execute the database query to manipulate the data appropriately.
iv.
Control is then usually forwarded back through the controller to the appropriate view. The view is responsible for the output of the model. A pure GUI view attaches to a model and renders its contents to the display surface.
Sarker: JMVC: A Java Framework for Rapidly Developing Desktop Application Software Based on MVC
260
//..file nmae Jmvcmodel.java public class Jmvcmodel { //... Member variables /** Constructor */ public Jmvcmodel() { }
}
Figure 3. JMVC model structure // ..file name Jmvcview.java public class Jmvcview extends JFrame { //... Constants & Components /** Constructor */ public Jmvcview(Jmvcmodel mymodel) { //... Layout the components. } }
Figure 4. JMVC view structure
//..file name Jmvccontroller.java public class Jmvccontroller { private Jmvcmodel jmvc_model; private Jmvcview jmvc_view; /** Constructor */ public Jmvccontroller(Jmvcmodel mymodel, Jmvcview myview) { jmvc _model = mymodel; jmvc _view = myview; //... Add listeners to the view. } }
Figure 5. JMVC controller structure
Smart Computing Review, vol. 4, no. 4, August 2014
261
Conclusion In this paper, we proposed a new framework to rapidly develop desktop application software based on MVC. A software developer can use this framework to build software rapidly. This framework facilitates reusing the design of part or the whole system, composed by a set of classes and instances interaction, has plug and play reusability, stability of maturity, and good teamwork. Using this JMVC framework not only achieves the complete separation of view, controller, and model of the MVC mode, but also separates the business logic layer and the persistence layer. Regardless of changes to the front end of the application, the model layer is not impacted, and database changes will not impact the front end. This environment helps team members work in parallel and improve the reusability of system. Actual operation has proved that this framework is stable, efficient, and safe.
References [1] W. Cui, L. Huang, L. J. Liang, J. Li, “The research of PHP development framework based on MVC pattern,” in Proc. of the 4th IEEE International Conference on Computer Sciences and Convergence Information Technology, pp. 247949, Seoul, Korea, Nov. 2009. Article (CrossRef Link) [2] MVC website, http://www.en.wikipedia.org/wiki/model-view-controller/. [3] Java website, http://www.en.wikipedia.org/wiki/Java_(programming_language)/. [4] A. Jain, J. Biesiadecki, “YAM - a framework for rapid software development,” in Proc. of the 2nd IEEE International Conference on Space Mission Challenges for Information Technology (SMC-IT'06), Pasadena, CA, 2006. Article (CrossRef Link) [5] S. Chang, J. Lee, W. Yi, “A practical management framework for commercial software development with open sources,” in Proc. of the IEEE International Conference on E-Business Engineering, pp. 174-171, Shanghai, China, Nov. 2010. Article (CrossRef Link) [6] R. Yongchang, X. Tao, X. Zhaofeng, Z. Jianchun, “Application research for integrated SSH combination framework to achieve MVC mode,” in Proc. of the IEEE International Conference on Computational and Information Sciences, pp. 499-502, Chengdu, China, Oct. 2011. Article (CrossRef Link)
Md. Iqbal Hasan Sarker received his Bachelors of Science in Computer Science & Engineering from Chittagong University of Engineering & Technology, Bangladesh, in 2009. He also completed his Masters of Science in Computer Science & Engineering from the same university in 2014. Currently he is working as an assistant professor at the same department and university. His research interests include Software Engineering, Mobile Applications, Web Applications and Data Mining.
Copyrights © 2014 KAIS