You are on page 1of 6

A Database and Web Application Based on MVC Architecture

Diana M. Selfa, Maya Carrillo, Ma. del Roco Boone


Facultad de Ciencias de la Computacin
Benemrita Universidad Autnoma de Puebla
14 Sur y Av.San Claudio, Edif. 135, Ciudad Universitaria
dselfa@hotmail.com, mayacar@siu.buap.mx, rboone@cs.buap.mx

Abstract problem model is considerably far form the solution


model effort will be invested in trying to transfer the
MVC architecture has had wide acceptance for problem representation from a users understandable
corporation software development. It plans to divide form to a designers and developers understandable one.
the system in three different layers that are in charge This causes misunderstandings and difficulty to
of interface control logic and data access, this validate the solution with regard to the established
facilitates the maintenance and evolution of systems problem [6].
according to the independence of the present classes in On the other hand a software engineer applies
each layer. With the purpose of illustrating a potential solutions to development problems, monitors
successful application built under MVC, in this work their success or failure and produces more effective
we introduce different phases of analysis, design and solutions on the next occasion.
implementation of a database and web application Different developers may expend a great deal of
using UML. As central component of the application, it development time and effort on solving these problems
has a database made up by fifteen relations and a user from first principles each time they occur, and the
interface supported by seventeen web pages. solution that each produce may not be the most
appropriate that could be achieved. Patterns provide a
Key words: MVC architecture, database systems, means for capturing knowledge about successful
analysis and system design. solutions in the software development.
One of these patterns is Model View Controller
1. Introduction (MVC) architecture initially introduced for user
interfaces in application implemented with the
In software development the modeling and the programming language Smalltalk. In this approach the
standardized notations allow to express complex ideas system is divided in three components: model that
in a precise way, facilitating the communication among express the domain knowledge, view that present the
the project participants that generally have different user interface, and control that manage the updates to
technical and cultural knowledge. views.
A notation should have a good defined semantics MVC has demonstrated its benefits for interactive
and should be dominated by the participants so that it applications allowing multiple representations of the
facilitates the communication. The established same information, promoting the code reutilizacin,
standards allow overcoming bad interpretations and and helping developers to concentrate on a single
ambiguity [1]. application aspect. [2]
Systems analysis and design produce models built It is common that information systems should be
by means of diagrams that use a specific notacin. tailored to different user needs according to their role.
UML is mainly a graphic language to represent the This means that if several users need to access assets
concepts that are needed in the development of an information it is probable that a person in charge of
object-oriented information system. inventory needs to see the amount of equipments, their
Models help to understand and to represent the distribution and who preserves them. However the
problem that is solved, as well as the problem solution. responsible for budget needs to know how much it has
Different approaches exist to model a problem and to been spent year to date in the acquisition of new assets.
express the system requirements and restrictions. If the This situation is translated in having different views for

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE
In this approach the text of the use cases is used to
identify the participant objects and they are classified
Controller according to the role that they play in the use case.
This classification locates the objects in a natural way
User inside the components of MVC. Ivar classifies the
objects in:
Model 1. Entity objects: objects with long life times related
View with persistent data, they can be databases tables, files,
and cache or session data (MVC model)
2. Boundary objects: objects that communicate to
Figure 1. MVC Architecture the system with their environment, they can be screens,
windows, menus, or any graphic interface element
(MVC view)
the same information that will be shown according to 3. Control objects: objects that carry out the use
the user. If a view is updated, the results of this update case actions are used to filter out the data to be
should be reflected in the remaining views. To think presented to the user (MVC control)
about having an architecture based on subsystems like This analysis imposes the following rules:
for example equipment subsystem, locations 1. Actors can only talk to boundary objects.
subsystem, budget subsystem can be expensive since 2. Boundary object can only talk to controllers and
several elements can be duplicated, making the actors
software more complex and prone to errors. The 3. Entity objects can only talk to controllers
system maintenance also gets complicated so that any 4. Controllers can talk to boundary objects and
change in the functionality of the system has to be entity objects, and to others controllers, but not to
changed in the subsystems interfaces. So the problems actors [11].
to be resolved are: In this work, we present like case study a database
1. The same information should be shown in and Web application (SAF) to control the assets
different formats in different views information owned by an educational institution. Its
2. Changes in a view should be reflected in the modeling was made using UML (Unified Modeling
remaining ones Language), it was used analysis of robustness and
3. Changes in the user interface should be easy to MVC architecture.
make In this paper we present MVC architecture. Section
4. The central functionality of the system should be three describes SAF specification aspects. Sections
independent of the interface to allow that multiple four, five, and six describe SAF view, control, and
interfaces coexist [1] model components respectively. Conclusions and
The MVC architecture solves the mentioned points perspectives of this work are in the last section.
separating the system functionality from the system
interface and it incorporates a mechanism for
propagating the changes to the remaining systems 2. MVC
views. Then their advantages with relationship to other
architectures are: The Model View Controller (MVC) paradigm was
1. Less coupling first designed for user interfaces in applications
2. Higher cohesion implemented with Smalltalk, but from then it has
3. The views provide bigger flexibility and agility: become a design paradigm for user interfaces without
multiple model views can be created, to add, to caring the implementation language and for web
modify, and to eliminate new views dynamically, you applications whose control components frequently
can nest views, you can change the way in which a change.
view responds to the user without changing its visual MVC architecture is illustrated in Figure 1, it divides
representation, to synchronize the views, to have views the interactive system in three components each one
for different devices according to their capacities, a specialized in a task. The model contains the
view for Web and another for windows applications application data and manages the core functionality.
4. More design clarity The view manages the visual display of the model and
5. It facilitates the maintenance the feedback to the user. The controller interprets the
6. Bigger scalability [5, 10] mouse and keyboard inputs from the user,
The analysis of robustness introduced by Ivar commanding the model and the view to change
Jacobson [7] can be easily moved to MVC architecture. appropriately [3].

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE
password to enter the system, 2. Manage assets
information administers assets information, 3. Manage
system catalogs administers information related to the
Validate Access
assets: accounts, people responsible for assets,
locations, assets classes, assets types, assets models,
Manage Assets Information
organizations among other, and 4. Generate reports
presents reports by classification, location, asset type,
Responsible people in charge of assets, serial number, inventory
for Inventory label and accounts as well as combinations of the
Manage System Catalogs
listing attributes.
Once defined the use cases in detail we use the
robustness analysis introduced by Ivar Jacobson [7].
Generate Reports Robustness analysis rules were applied in SAF
analysis and design. Figure 3 shows a simplified
Figure 2. SAF main use cases diagram for Delete Account use case related to Manage
System Catalogs by a relation << uses >>. The view is
The pattern may be passive, which means that it represented by an HTML page named Cuentas. When
does not know about the existence of the view or the the user selects the delete option of the datagrid
controller. For example if the model is a text that can (grdCuentas) on the HTML page to eliminate an
only be changed by the user. However in most of the element a message is sent to PrvControl who sends the
cases the model must have a link to the view to inform message prvBorrar to MdPrincipal. This last one send
it on changes made to its state caused by internal the message execute to the control SqlClient that is the
procedures. The view and the controller are always .NET framework Data provider [13] who by means of
connected. The controller communicates with the view SAF_SP_CUENTA stored procedure erases the
to determine which objects are being manipulated by selected element.
the user and to call model methods to make changes on Starting from the robustness diagrams classes,
these objects. The model carries out the changes and it sequence, collaboration and states diagrams were built.
notifies the view to update. SAF was implemented in ASP.NET [8] that is coupled
The application view generally includes several to the MVC paradigm separating the interface (view)
nested MVC views. The controllers of these views in a natural way in file * .aspx and code behind page
should cooperate to assure that the appropriate control (control) in files * .aspx.yy, where yy depends on the
is interpreting the user entrance. For this purpose they programming language, in our case it was Visual Basic
form a hierarchical tree where the messages pass from .NET. SQL Server 2000 was used as relational
controller to controller through the branches of the tree. database [13, 14] and Crystal Report to generate
Only the controller that has the focus takes an action. reports. The main functions of the system are:
Each view is associated with a unique controller and
vice versa, but the model can have at the same time
more than one view-controller pair. Every time that the
model changes each dependent view must be notified
so that they change accordingly. The possibility to
grdCuentas_
have multiple synchronized views is a significant DeleteCommand
benefit of the MVC architecture [4]. Cuentas

3. SAF
We present the case study SAF an application to PrvControl
manage assets information for illustrating the use of
the MVC architecture.
UML was used as modeling language, since it has
become an industry standard, we use it to carry out the MdPrincipal
models of the system.
Trying to diminish the breach between the problem SqlCliente
model and the solution model use cases were used for
eliciting SAF requirements. Figure 2 shows the main Figure 3. Conceptual robustness diagram for
use cases: 1. Validate access requests user and Delete Account use case

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE
layer with SAF_SP_CUENTA a stored procedure as
parameter.
SQL Private Sub prvBorrar()
Server
If Me.grdCuentas.SelectedIndex <> -1 Then
Database Server Me.txtClave.Text =
Me.grdCuentas.SelectedItem.Cells(1).Text
Me.txtCuenta.Text =
Me.grdCuentas.SelectedItem.Cells(2).Text
If Ejecuta("SAF_SP_CUENTA 3, " &
Me.grdCuentas.SelectedItem.Cells(0).Text & "," &
Web Clients Me.txtClave.Text & ", '" &
UCase(Me.txtCuenta.Text) & "'") Then
prvEstadoInicial()
Internet Information Server (IIS) Else
Me.lblResultados.Text = "Ha ocurrido un error al
Figure 4. SAF Distribution intentar
End If
End If
1. Validate access, 2. Manage catalogs: assets type, End Sub
accounts, classifications, locations, organizations,
measure units, principals, people in charge of assets, 5. Model
acquisition types, marks, models, conservation states
and users. 3. Manage assets 4. Generate reports, and 5. In the model we find the class MdPrincipla with 3
Maintain assets historical. main methods: ejecuta, consulta, and insertaConClave
Figure 4 shows SAF distribution: an ASP pages and 17 stored procedures. Next the ejecuta method
server, a database server, and clients that will be able code is shown. Ejecuta method was called by the
to use the application according to their authorization Control using the prvBorrar method. It can be observed
level using a browser. that until this layer the application makes use of
specific classes to communicate with the selected
4. View database.

The system interface consists of 17 web pages 13 of Public Function Ejecuta(ByVal vsInstruccion As String) As
them for catalogs administration. They allow Boolean
homogenizing the assets information. Figure 5 shows If gnNivelUsuario > 0 Then
Try
the page for administering account catalog. In each line
goConeccion = New SqlClient.SqlConnection("DATA
of a datagrid you can see the registered accounts if X is SOURCE=localhost;initial
selected the element of the line is deleted. If E is catalog=saf;uid=saf;pwd=userSAF;")
selected the key account and the description account goConeccion.Open()
are placed in the corresponding text box and you are goComando = New
allowed to modify them. If the new button is pressed SqlClient.SqlCommand(vsInstruccion, goConeccion)
the text boxes of key account and description account goComando.ExecuteNonQuery()
are activated to be edited with information of a new Ejecuta = True
account. This information is save to the database when Catch e As System.Exception
Return False
the accept button is pressed.
Finally
goComando = Nothing
5. Control goConeccion.Close()
End Try 'de Try
Controls are constituted by the * .aspx.vb files one Else
for each web pages developed, in them there are 12 Return False
methods on average that contain the logic for event End If
End Function
handling and an additional control to communicate
with the model and to returns data to page control. Like
As it was previously mentioned in SQL Server 2000
example part of the PrvControl class code is shown.
17 store procedures were created to add, to update, to
This code allows eliminating a catalog account. It can
delete, and to search on the database tables. The store
be observed the call to the ejectua method of the model

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE
to have a historical registration for people in charge of
an asset and asset characteristics at the assignment
moment. To implement this requirement it was only
necessary to modify the model and the view of the
application. A trigger associated to SAFDBIEN assets
table was added in the model to validate the moment
when the person responsible of the asset, asset
characteristics or asset state is updated to insert a new
record into SAFDHIST historical table. Trigger code to
insert a record into SAFDHIST when the asset
characteristics are changed is shown:

CREATE TRIGGER SAF_TG_HISTORIAL ON


dbo.SAFDBIEN
AFTER UPDATE
AS
Figure 5. SAF interface IF EXISTS (SELECT * FROM INSERTED
JOIN DELETED ON INSERTED.DSCARAC <>
DELETED.DSCARAC)
procedure SAF_SP_CUENTA operates on the
INSERT INTO SAFDHIST
SAFCCUENTA table. It can be stood out that until this SELECT INS.PNCLAVE, 1,
level a specific SQL syntax is used. INS.DSCARAC, INS.FNRESP,
GETDATE(), INS.FNUSUARIO,
CREATE PROCEDURE SAF_SP_CUENTA INS.FNEDO
@VNOPCION TINYINT, FROM INSERTED INS
@VNCLAVEUNICA INTEGER, JOIN DELETED ON
@VNCLAVE INT, INS.PNCLAVE = DELETED.PNCLAVE
@VSDESCR VARCHAR(20)
AS Similar code was written to insert a record if the
IF (@VNOPCION = 1)
person in charge of the asset or the asset state is
INSERT INTO
SAFCCUENTA(DNCLAVE, DSDESCR) updated. The easiness to implement changes like the
VALUES described has shown the advantages of MVC
(@VNCLAVE, @VSDESCR) architecture.
END To have a better idea about the objects in model
IF (@VNOPCION = 3) BEGIN layer, table 1 shows the system database tables and
DELETE their description.
SAFCCUENTA
WHERE
PNCLAVE = @VNCLAVEUNICA 6. Conclusions
END
Through the development of the application that we
GO have presented in this work, we confirm the advantages
of MVC architecture for database and web application
Some of our experiences when developing this development. It was also evident that the construction
system were that use case diagrams used to specify the of clear and understandable models for the users and
system functionality from the user perspective together software engineers allows the construction of quality
with robustness analysis are a powerful tool to track systems with predictable development times. With
each requirement since its definition up to its regard to the case study presented in this work we will
implementation and tests. The use of programming incorporate new components to allow the capture of
standards to write code reflected in the names of web computer assets in an automatic way to feed and
pages, variables, tables, stored procedures, triggers and update the database, this means that using the network
methods gave as a result an understandable and simple infrastructure computer hardware and software
code. Also the code organization in three layers has characteristics will be captured. These characteristics
allowed other developers quickly understand its will be used to obtain performance and space
structure facilitating the changes implementation. distribution graphics.
During application development we received several
changes from the user; one of them was the possibility

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE
[15] C. Larman: UML y Patrones: Introduccin al anlisis y
Table 1. SAF database tables diseo orientado a objetos. Prentice-Hall Hispanomericana,
1999.
Table name Description
SAFCCLAS Asset Classification
SAFCCUENTA Accounts
SAFCDIR Principals
SAFCEDO Asset State
SAFCMARCA Brands
SAFCMOD Models
SAFCORG Organizations
SAFCRESP People in charge of assets
SAFCTIPO Asset Type
SAFCTIPOAD Acquisition Type
SAFCUBI Locations
SAFCUNIDAD Departments
SAFCUSU Users
SAFDBIEN Assets
SAFDHIST Asset historical

7. References
[1] Simon Bennett, Steve McRobb, Ray Farmer. Object-
Oriented systems Analysys And design Using UML, Mc
Graw Hill.
[2] Colin Moock, Object-Oriented Development with
ActionScript 2.0, OReilly
[3] S. Burbeck, Applications Programming in Smalltalk-80:
How to use Model-View-Controller (MVC), http://st-
www.cs.uiuc.edu/users/smarch/st-docs/mvc.html,
(1992). Referred 19.11.2002.
[4] Hanna Dobos, Separable User Interfaces and Interaction
Controls, Masters Thesis, University of Jyvskyl,
Department of Mathematical Information Technology, 2002
[5] Len Welicki, Patrones y Antipatrones: una Introduccin
- Parte II, http://www.microsoft.com/spanish/msdn/
comunidad/mtj.net/voices/MTJ_3317.asp
[6] Philippe Kruchten, The Unified Process an Introduction,
Addison Wesley.
[7] Ivar Jacobson, Objet Oriented Software Engineering,
ACM Press.
[8] G.Andrew Duthie. ASP.NET, McGraw-Hill, 2002
[9] J.Rumbaugh, I. Jacobson, G.Booch. El lenguaje
Unificado de Modelado. Manual de Referencia, 2000
[10] C. Larman: UML y Patrones: Introduccin al anlisis y
diseo orientado a objetos. Prentice-Hall Hispanomericana,
1999.
[11] Shams Mukhtar, Applying Robustness Analysis on the
ModelViewController (MVC) Architecture in ASP.NET
Framework, using UML, http://www.codeproject.com/
aspnet/ModelViewController.asp
[12] K. Delaney. Inside SQL Server 2000, Microsoft 2001
[13] R.Dobson. Programming Microsoft SQL Server 2000
with Microsoft Visual Basic .NET, Microsoft 2002.
[14] D. Sceppa. Programming ADO, Microsoft 2000

Proceedings of the 16th IEEE International Conference on Electronics, Communications and Computers (CONIELECOMP 2006)
0-7695-2505-9/06 $20.00 2006 IEEE

You might also like