You are on page 1of 48

Model-View-Controller:

A Design Pattern for Software


June 2004

Introduction

!" focus on Model-View-Controller Arc!itecture#

!at$s a Software Design Pattern#

!" s!ould %rogra&&ers care a'out Design


Patterns#

!" focus on Model-View-
Controller Arc!itecture#
(!e to%ic of t!is %resentation is MVC - Model-View-Controller - arc!itecture in we'
a%%lications) (!is to%ic was selected 'ecause it allows us to loo* at we' a%%liation
de+elo%&ent in o+er+iew, 'efore getting into t!e nitt" gritt" of t!e &an" co&%onent
%arts of i&%le&enting a we' a%%)
MVC is a funda&ental and !ig!-le+el design %attern for %rogra&&ing in t!e J2--
arc!itecture toward w!ic! t!e .C /er*ele" ca&%us is gra+itating in res%onse to t!e
--Arc!itecture guidelines esta'lis!ed '" t!e ca&%us$s Infor&ation (ec!nolog"
Arc!itecture Co&&ittee 0I(AC1 in 2002)

!at$s a Software Design
Pattern#
(!e idea of Design Patterns in software engineering grew out of wor* '" -&eritus
Professor C!risto%!er Ale3ander of .C /er*ele"$s own arc!itecture de%art&ent)
Professor Ale3ander$s ideas were &ost nota'l" a%%lied to Software -ngineering '"
four aut!ors of t!e 'oo* Design Patterns: -le&ents of 4eusa'le 5'6ect-5riented
Software, collecti+el" nic*na&ed t!e 78ang of 9our)7 (!is 'oo* identifies a'out
two do:en funda&ental %atterns for sol+ing recurring %ro'le&s in software
engineering)
/rad A%%leton$s article Patterns and Software: -ssential Conce%ts and (er&inolog"
gi+es a good o+er+iew of Design Patterns a%%lied to software %rogra&&ing) (!e
Design Patterns))) 'oo*, '" -ric! 8a&&a, 4ic!ard ;el&, 4al%! Jo!nson, and Jo!n
Vlissides, is a resource of inesti&a'le +alue)

!" s!ould %rogra&&ers care
a'out Design Patterns#
It !as 'eco&e widel" acce%ted a&ong software engineers and arc!itects t!at designing
a%%lications in e3%licit confor&it" to t!ese %atterns facilitates t!e re-use of insig!t and
e3%erience gleaned '" t!e 'est and 'rig!test a&ong us o+er t!e course of t!ousands of
real-world software de+elo%&ent efforts)
In s!ort, t!in*ing in ter&s of Design Patterns will &a*e "ou a 'etter %rogra&&er)

!at is MVC#
MVC - Model-View-Controller - is a design %attern for t!e arc!itecture of we'
a%%lications) It is a widel" ado%ted %attern, across &an" languages and i&%le&entation
fra&ewor*s, w!ose %ur%ose is to ac!ie+e a clean se%aration 'etween t!ree co&%onents of
&ost an" we' a%%lication:
In general, J2--
a%%lications - including
t!ose 'uilt on to% of t!e
Stree* %ro6ect - follow
t!e MVC design %attern)
8eneric MVC Structure, courtes" of Sun 0
!tt%:<<6a+a)sun)co&<'lue%rints<%atterns<MVC-detailed)!t&l1
Model: 'usiness logic = %rocessing
View: user interface 0.I1
Controller: na+igation = in%ut

!at are t!e 'enefits of MVC#
MVC 'enefits fall into &ulti%le categories:
Se%aration of concerns in t!e code'ase
De+elo%er s%eciali:ation and focus
Parallel de+elo%&ent '" se%arate tea&s
In loo*ing at t!ese in a little &ore detail, it will 'eco&e clear t!at t!e second
two 'ullet-%oints are corollaries of t!e first)

Se%aration of concerns 021
Se%aration of Model, View, and Controller:
allows re-use of 'usiness-logic across a%%lications
allows de+elo%&ent of &ulti%le .Is wit!out touc!ing 'usiness logic code'ase
discourages 7cut-=-%aste7 re%etition of code, strea&lining u%grade = &aintenance
tas*s
>oo*ing at t!e ot!er side of t!e sa&e coin, inter&ingling M, V, and C code &a*es for:
'igger, *narlier, !arder-to-&aintain classes
re%etition of code in &ulti%le classes 0u%grade = &aintenance issues1

Se%aration of concerns 021
;ere$s a sni%%et of w!at Martin 9owler, a res%ected and &uc!-%u'lis!ed aut!or of
design-oriented software literature, !as to sa" on t!e su'6ect of se%aration of concerns:
Following this principle leads to several good results. First, this presentation code
[View] separates the code into different areas of complexity. Any successful
presentation requires a fair bit of programming, and the complexity inherent in that
presentation differs in style from the domain [odel] with which you wor!. "ften it
uses libraries that are only relevant to that presentation. A clear separation lets you
concentrate on each aspect of the problem separately#and one complicated thing at a
time is enough. $t also lets different people wor! on the separate pieces, which is useful
when people want to hone more speciali%ed s!ills.
- Martin 9owler, &eparating 'ser $nterface (ode
!tt%:<<www)&artinfowler)co&<ieeeSoftware<se%aration)%df

De+elo%er s%eciali:ation and
focus

.I de+elo%ers can focus e3clusi+el" on .I, wit!out getting


'ogged down in 'usiness logic rules or code

/usiness logic de+elo%ers can focus on 'usiness logic


i&%le&entation and c!anges, wit!out !a+ing to slog t!roug! a
sea of .I widgets

Parallel De+elo%&ent '"
Se%arate (ea&s
/usiness logic de+elo%ers can 'uild 7stu'7 classes t!at allow .I de+elo%ers to forge
a!ead 'efore 'usiness logic is full" i&%le&ented)
.I can 'e rewor*ed as &uc! as t!e custo&er re?uires wit!out slowing down t!e
de+elo%&ent of code t!at i&%le&ents 'usiness rules)
/usiness rule c!anges are less li*el" to re?uire re+ision of t!e .I 0'ecause rule
c!anges don$t alwa"s affect structure of data t!e user sees1 )

APIs: Contracts t!at /ind

APIs: (!e 8lue 'etween Model, View, and Controller

Si&%le MVC -3a&%le

Controller can call &et!ods on &odel in different wa"s

Model can read<write fro& different or &ulti%le data'ases



APIs: (!e 8lue 'etween Model,
View, and Controller
7Se%aration of concerns7 &eans t!at one la"er doesn$t care !ow anot!er la"er is
i&%le&ented
-ac! la"er relies sole" on t!e 'e!a+ior s%ecified in t!e API of ot!er la"ers)
(!e API s%ecifies t!e 'e!a+ior of t!e interface 'etween a la"er and t!e la"ers t!at
interact wit! it)
(!e APIs &a" 'e considered contracts to w!ic! eac! de+elo%&ent tea& agrees 'efore
going off to i&%le&ent t!e 'e!a+ior %ro&ised '" t!e interface)

Si&%le MVC -3a&%le

Controller can call &et!ods on
&odel in different wa"s
(!e controller can call w!ate+er &odel &et!ods it wis!es to acco&%lis! t!e desired 'e!a+ior

Model can read<write fro&
different or &ulti%le data'ases
(wo wa"s to %ersist contact infor&ation

Model 0Detail1
(!e a%%lication@s &odel includes:

A%%lication State

A%%lication 4ules

Persistent data

A%%lication State
(!e data &odel re%resents t!e 7noun7 o'6ects needed '" t!e a%%lication and<or its
users, suc! as:
%eo%le 0facult", staff, students, custo&ers, +isitors, a%%lication ad&inistrators1
widgets needed '" a%%lication users 0s!o%%ing carts, transcri%ts, contact infor&ation,
&erc!andise1
(!e data &odel defines t!ese o'6ects a'stractl")
(!e instances of t!e data o'6ects currentl" in-%la", and t!e +alue of t!ose o'6ects,
constitutes t!e 7a%%lication state)7

A%%lication 4ules
A%%lication rules are t!e 'usiness logic of t!e a%%lication)
-3a&%les of 'usiness logic are:

A student &a" not alter t!e data in !er transcri%t

5nl" t!e student !erself and a%%lication ad&inistrators &a"


&odif" a student$s contact infor&ation

A facult" &e&'er &a" +iew a student transcri%t onl" if s!e


is t!e student$s designated ad+isor

Persistent data 021
Persistence refers to long-ter& storage of data - 'e"ond t!e sco%e and ti&e-fra&e of t!e
user$s session in t!e a%%lication)
Persistence is ta*en care of 7'e!ind t!e facade7 of t!e data &odel) (!at is, t!e
a%%lication$s Model la"er e3%oses a facade re%resenting t!e data &odelA and 'e!ind-t!e-
scenes t!e Model ta*es care of reading = writing data t!at %o%ulates instances of t!e
&odel o'6ects)
If t!e data store used '" t!e a%%lication c!anges 0fro& flat files to a relational data'ase,
for e3a&%le1, ot!er la"ers of t!e a%%lication 0suc! as t!e View1 don$t need to 'e altered:
t!e" are s!ielded fro& %ersistence details '" t!e Model facade)

Persistent Data 021
(!e %ersistence la"er is %art of t!e Model

Model I&%le&entation
(ec!nologies
it!in t!e J2-- fra&ewor*, t!ere are a range of tec!nologies t!at &a" 'e a%%lied to
i&%le&entation of t!e &odel la"er) (!ese include:
5'6ect-4elational Ma%%ing 9ra&ewor*s 0Ja+a 5'6ects B-C 4elational Data'ases1:
;i'ernate, an o%en-source %ersistence fra&ewor*
5racle$s (o%>in*
Sun$s -J/ 0-nter%rise Ja+a /eans1
Sun$s JD5 0Ja+a Data 5'6ects1
;and-coded data accessors +ia t!e JD/C API
(!e attri'utes and &erits of eac! of t!ese solutions are outside t!e sco%e of t!is
%resentation) In general, !owe+er, 5'6ect-4elational &a%%ing fra&ewor*s in+ol+e a
la"er of a'straction and auto&ation 'etween t!e a%%lication %rogra&&er and data
%ersistence, w!ic! tends to &a*e a%%lication de+elo%&ent faster and &ore fle3i'le)
Differences 'etween s%ecific 5-4 Ma%%ing tec!nologies turn on t!e arra" of ser+ices
offered '" eac! tec!nolog", +endor s%ecificit", and !ow well t!ese differences &a% to a
%articular a%%lication$s de+elo%&ent and de%lo"&ent re?uire&ents)

View 0Detail1

-le&ents of t!e View

View (ec!ologies

(e&%lating

St"ling

(!e Decorator Pattern



-le&ents of t!e View
(!e a%%lication$s View is w!at t!e user sees) In a we' a%%lication, t!e View
la"er is &ade u% of we' %agesA in a we' a%%lication t!at can 'e accessed '"
non-traditional 'rowsers, suc! as PDAs or cell-%!ones, t!e View la"er &a"
include user interfaces for eac! su%%orted de+ice or 'rowser t"%e)
In an" case, t!e View includes:
Core data - t!e su'6ect of a %age$s 'usiness
/usiness logic widgets 0e)g), 'uttons to %erfor& -dit or Sa+e1
Da+igation widgets 0e)g), na+igation 'ar, logout 'utton1
S*in 0standard loo* of t!e site: logos, colors, footer, co%"rig!t, etc)1

View (ec!nologies 021
In t!e conte3t of a we' a%%lication, +iew tec!nologies are used to render t!e user
interface 0.I1 in a wa" t!at %ro%erl" and d"na&icall" lin*s it to t!e a%%lication$s
'usiness-logic and data la"er 0i)e), to t!e &odel1)
Java Server Pages 0JSPs1 are a widel"-utili:ed tec!nolog" for constructing d"na&ic we'
%ages) JSPs contain a &i3 of static &ar*u% and JSP-s%ecific coding t!at references or
e3ecutes Ja+a) In 'rief:
JSP (ags call co&%iled Ja+a classes in t!e course of generating d"na&ic %ages)
JSP Directi+es are instructions %rocessed w!en t!e JSP is co&%iled) Directi+es set
%age-le+el instructions, insert data fro& e3ternal files, and s%ecif" custo& tag
li'raries)
Ja+a code - in sections called 7scri%tlets7 - can 'e included in JSP %ages directl",
'ut t!is %ractice is strongl" discouraged in fa+or of using JSP (ags

View (ec!nologies 021
XML Pipelining is anot!er tec!ni?ue for rendering t!e .ser Interface) A%ac!e$s
Cocoon and 5r'eon$s 5E9 are tec!nologies t!at use t!is tec!ni?ue) 09or t!e
record, EM> %i%elining si&%l" &eans e3ecuting a series of transfor&ations of
EM> docu&ents in a %roscri'ed order) 9or e3a&%le, a data structure %ulled fro&
a %ersistent store &a" 'e rendered as an EM> docu&ent, t!en - in a %i%eline -
&a" 'e aug&ented wit! data fro& a se%arate data structureA sortedA and rendered
in ;(M> for&at using a series of ES>( transfor&ations) A si&%le e3a&%le of
an EM> %i%eline using A%ac!e$s Ant tool can 'e +iewed in t!is article)1

(e&%lating
In order to &aintain a consistent loo*-and-feel on a site, %ages are often te&%lated)
(!e we' %age$s B'od"C is w!ere core 'usiness content of a %age can 'e found) .sing a
te&%late to render a consistent !eader, footer, and na+igation .I around t!e core 'usiness
content standardi:es a site$s gra%!ic %resence, w!ic! tends +er" strongl" toward &a*ing
users$ e3%erience s&oot!er and less %rone to error)
)emplated web*page layout, courtesy of &un

St"ling e' Pages wit! CSS
Cascading St"le S!eets are a critical co&%onent of rendering a consistent loo* and
feel in a we' site 0cf) t!is CSS (utorial for &ore on Cascading St"le S!eets1)
CSS is used to s%ecif" colors, 'ac*grounds, fonts and font-si:e, 'loc*-ele&ent
align&ent, 'orders, &argins, list-ite& &ar*ers, etc) /" s%ecif"ing t!e designer$s
c!oices in a single file 0or grou% of files1, and si&%l" referring to t!e st"le s!eet0s1
in eac! we' %age, c!anges in st"le can 'e acco&%lis!ed wit!out altering t!e %ages
t!e&sel+es)
(!e 'readt! of design c!oices t!at can 'e ac!ie+ed si&%l" '" a%%l"ing different
CSS to a we' %age is +i+idl" illustrated at t!e CSS Fen 8arden we'site)

(!e Decorator Pattern 021
(e&%lating and st"ling are as%ects of an i&%ortant 78ang of 9our7 design %attern, called
t!e Decorator Pattern) .sing t!e Decorator Pattern si&%l" &eans wra%%ing so&e core
o'6ect in so&et!ing t!at gi+es it additional functionalit") In t!e conte3t of 'uilding a user
interface for t!e we' - t!e View la"er of an MVC-arc!itected a%%lication - t!is &ig!t
&ean wra%%ing:
core 'usiness infor&ation in a
te&%late 0e)g), !eader G footer G na+igation1, w!ic! includes 0in t!e co&&on
;(M> !eader1 reference to a
CSS st"les!eet 0w!ere 'ac*ground, colors, fonts, etc) are s%ecified1
In order to i&%le&ent t!is design %attern in t!e +iew la"er, %age decorating fra&ewor*s,
suc! as 5%enS"&%!on"$s SiteMes! can si&%lif" t!e %rocess) SiteMes! interce%ts ;(M>
%ages %roduced staticall" and<or d"na&icall", and a%%lies a unifor& 7s*in7 to t!e&, as
s%ecified in configuration files)
;ere$s a diagra& s!owing !ow SiteMes! wor*s)

(!e Decorator Pattern 021
!tt%:<<www)o%ens"&%!on")co&<site&es!<

(!e Decorator Pattern 0H1
e' %age generation in a local J2-- a%%lication

Controller Detail

4es%onsi'ilities of t!e Controller

Controller (ec!nologies

4es%onsi'ilities of t!e Controller
(!e Controller will do t!e following:
Parse a user re?uest 0i)e), 7read7 it1
Validate t!e user re?uest 0i)e), assure it
confor&s to a%%lication$s re?uire&ents1
Deter&ine w!at t!e user is tr"ing to do
0'ased on .4>, re?uest %ara&eters,
and<or for& ele&ents1
5'tain data fro& t!e Model 0if
necessar"1 to include in res%onse to user
Select t!e ne3t View t!e client s!ould
see
(!e se?uencing of calls to t!e Model
0'usiness-logic la"er1, and<or t!e se?uencing
of +iews and re?uired in%ut fro& t!e user
defines t!e a%%lication$s wor*flow) or*flow
is t!us defined in t!e Controller la"er of t!e
a%%lication)
(!e Controller la"er is, essentiall", a traffic co%)))

Controller (ec!nologies
(!ere are nu&erous a%%lication fra&ewor*s t!at can 'e used to
%ro+ied t!e control la"er in an MVC-arc!itected a%%lication)
(!ese include:

Struts

Ja+a Ser+er 9aces

e'or*

S%ring
!ic! of t!ese 0or ot!ers1 is &ost a%%ro%riate to an a%%lication is
a ?uestion to discuss wit! an e3%erienced a%%lication arc!itect)

De%lo"&ent Descri%tors:
9unction

!at De%lo"&ent Descri%tors Do

De%lo"&ent Descri%tors are Declarati+e

Additional -3ternali:ation

!at De%lo"&ent Descri%tors Do
A 7De%lo"&ent Descri%tor7 is a configuration file) It is not code, and it is ne+er
co&%iled)
De%lo"&ent Descri%tors are used to configure an a%%lication as it starts u% in its
container 0i)e), in its a%%lication ser+er1) Configuring an a%%lication includes wiring
its co&%onents toget!er: declaring w!at res%onses corres%ond to w!ic! re?uests)
In t!e J2-- en+iron&ent, t!e &ot!er of all de%lo"&ent descri%tors is t!e file
we')3&l) (!e contents of t!is file are s%ecified in t!e Ja+a Ser+let s%ecificationA
de%ending on t!e +ersion of t!e s%ecification t!e file &ust confor& to a %articular
D(D or ESD:
D(D for Ser+let S%ec 2)H we')3&l
ESD for Ser+let S%ec 2)4 we')3&l

De%lo"&ent Descri%tors are
Declarati+e
De%lo"&ent Descri%tors are 7declarati+e7 and are utili:ed in t!e conte3t of J2--$s
declarati+e %rogra&&ing &odel) !at t!at 'oils down to is t!at:
Man" of t!e i&%ortant attri'utes of J2-- classes are not !ard-coded
De%lo"&ent Descri%tors are read w!en t!e co&%onents are started 0de%lo"ed1, and
used to configure de%lo"ed &odules and classes
(!is &eans one can declare 0+ia t!e De%lo"&ent Descri%tor1 w!at suc! attri'utes
oug!t to 'e wit!out c!anging or reco&%iling an" code)
(!e attri'utes in ?uestion are ones t!at s%ecif" a%%lication co&%onents, wor*flow,
securit", etc)
(!ere$s not!ing &agical a'out t!is in t!e J2-- fra&ewor*) !at$s i&%ortant is t!at &an"
of t!e attri'utes t!at &ig!t !a+e 'een !ard-coded in older fra&ewor*s are, in J2--,
7e3ternali:ed)7 -3ternali:ation allows a%%lications to 'e &ore &odular)

Additional -3ternali:ation
Additional e3ternali:ation is 'uilt on t!e %attern esta'lis!ed
wit! we')3&l) Additional functionalit" declared outside outside
t!e a%%lication code'ase &ig!t include:
I %age flow - defined '" we' a%%lication fra&ewor*s suc! as
Struts
I %age decoration 0s*ins1 - are defined '" we' %age la"out
and decoration fra&ewor*s suc! as SiteMes!

/enefits of De%lo"&ent
Descri%tors 021
(!e c!ief ad+antage of e3ternali:ing configuration +ia De%lo"&ent Descri%tors is t!at t!e
'inding 'etween different &odules or la"ers is 7looser7A t!at is, c!anges can 'e
i&%le&ented wit!out rewriting or reco&%iling code)
De%lo"&ent Descri%tors can 'e used in J2-- a%%lications to s%ecif":
!ic! %ersistent data stores are to 'e used 0e)g), w!ic! data'ase on w!ic! !ost1
!ic! securit" fra&ewor* s!ould 'e used
!at securit" s!ould a%%l" to eac! %art of t!e a%%lication 0i)e), w!ic! user-roles
are aut!ori:ed to do w!at actions or see w!at %ages1
!ic! class s!ould !andle eac! user-re?uested .4>
!at t!e a%%lication wor*flow s!ould 'e
!ic! View %age s!ould 'e used to res%ond to eac! user re?uest, and !ow
a%%lication state 0+alues of data in t!e Model1 s!ould 'e ta*en into account in t!is
deter&ination
!ic! 7s*in7 s!ould 'e used to decorate eac! View %age %resented to t!e user

/enefits of De%lo"&ent
Descri%tors 021
9or e3a&%le, de%lo"&ent descri%tor ele&ents defining t!e Controller la"er of an
a%%lication &a% user-re?uested .4>s to t!e classes t!at will fulfill t!e re?uests) (!e
&a%%ing defines t!e a%%lication$s wor*flow) /ecause t!e &a%%ing is declared in a
De%lo"&ent Descri%tor, t!e wor*flow can 'e c!anged wit!out altering code, as in t!is
e3a&%le:
Workflow Changes for Secure Encryption Software On-line Purchase: t!e order in
w!ic! a user is %resented %ages can 'e e3ternali:ed in t!e De%lo"&ent Descri%tor

-3a&%le De%lo"&ent Descri%tor:
(!e ne3t slides s!ow an e3a&%le of a struts-config)3&l file, fro& t!e Stree* client
a%%lication /ear9acts) it!out getting into too &an" details, t!ese are t!e ste%s t!at
connect a user$s re?uest wit! t!e se?uence of actions descri'ed '" t!is de%lo"&ent
descri%tor:
At a%%lication startu%, Struts ActionSer+let is initiali:ed wit! data in struts-config)3&l
we')3&l de%lo"&ent descri%tor &a%s all .4> re?uests of t!is for& to a Struts
ActionSer+let 0w!ose class is also s%ecified in we')3&l1
.ser re?uests .4>, of t!e for& !tt%:<<Jconte3t-rootK<student<do<I
(!e action %at! is t!e %art of t!e .4> t!at follows 7student<do7
De%ending on t!e action-%at! %art of t!e re?uested .4>:
An 7Action Class7 s%ecific to t!e t"%e of o%eration re?uested is identified 0t!e
7t"%e7 attri'ute of BactionC1
(!e s%ecified 7Action Class7 calls a%%ro%riate Model classes to %erfor&s 'usiness
logic, %rocessing data 0e)g), for& data1 in t!e user$s re?uest
(!e View t!at t!e user will see ne3t is selected 'ased on w!ic! forward na&e
07na&e7 attri'ute of t!e BforwardC ele&ent1 is set as a result of %rocessing %erfor&ed
'" t!e Model class0es1

struts-config)3&l 02 of 21
B#3&l +ersionL72)07 encodingL7IS5-MMNO-27#C
BPD5C(QP- struts-config P./>IC 7-<<A%ac!e Software 9oundation<<D(D Struts Configuration 2)2<<-D7
7!tt%:<<6a*arta)a%ac!e)org<struts<dtds<struts-configR2R2)dtd7C
Bstruts-configC
Bglo'al-forwardsC
Bforward na&eL7s"ste&Message7 %at!L7<s"ste&Message)6s%7<C
B<glo'al-forwardsC
Baction-&a%%ingsC
Baction %at!L7<studentMain7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentMainAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7welco&e7 %at!L7<student<welco&e)6s%7<C
Bforward na&eL7logout7 %at!L7<login<logout)6s%7 redirectL7true7<C
B<actionC
Baction %at!L7<studentContact7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentContactAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7dis%la"Profile7 %at!L7<student<%ersonal<dis%la"Profile)6s%7<C
Bforward na&eL7dis%la"Contacts7 %at!L7<student<%ersonal<dis%la"Contact)6s%7<C
Bforward na&eL7u%dateContact7 %at!L7<student<%ersonal<u%dateContact)6s%7<C
Bforward na&eL7confir&Contact.%date7 %at!L7<student<%ersonal<confir&Contact.%date)6s%7<C
B<actionC
Baction %at!L7<registration7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student4egistrationAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7classSc!edules7 %at!L7<student<registration<classSc!edules)6s%7<C
Bforward na&eL7reg9eeSu&&ar"7 %at!L7<student<registration<reg9eeSu&&ar")6s%7<C
Bforward na&eL7su&&er4eg9ee7 %at!L7<student<registration<su&4eg9ee)6s%7<C
Bforward na&eL7registration/loc*s7 %at!L7<student<registration<registration/loc*s)6s%7<C
Bforward na&eL7final-3a&Sc!edule7 %at!L7<student<registration<final-3a&Sc!edule)6s%7<C
Bforward na&eL7tele'earsA%%oint&ent7 %at!L7<student<registration<tele'earsA%%oint&ent)6s%7<C
B<actionC
S)))T

struts-config)3&l 02 of 21
S)))T
Baction %at!L7<acade&ic4ecord7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentAcade&ic4ecordAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7current(er&8rades7 %at!L7<student<acade&ic<studentCurrent8rades)6s%7<C
Bforward na&eL7%rior(er&8rades7 %at!L7<student<acade&ic<studentPrior8rades)6s%7<C
B<actionC
Baction %at!L7<financialAid7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student9inancialAidAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7offer>etter7 %at!L7<student<fin-aid<fin-aid-offer)!t&l7<C
Bforward na&eL7financialAidStatus7 %at!L7<student<fin-aid<finaidStatus)6s%7<C
Bforward na&eL7financialAidAwardSu&&ar"7 %at!L7<student<fin-aid<finaidAwardSu&&ar")6s%7<C
Bforward na&eL7&issingDocu&ents7 %at!L7<student<fin-aid<finaidMissingDocs)6s%7<C
B<actionC
Baction %at!L7<CA4S7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)StudentCA4SAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7classSc!edules7 %at!L7<student<%ersonal<classSc!edules)6s%7<C
Bforward na&eL7refundSu&&ar"7 %at!L7<student<cars<refundSu&&ar")6s%7<C
Bforward na&eL7awardsSu&&ar"7 %at!L7<student<cars<awardsSu&&ar")6s%7<C
Bforward na&eL7%a"&entSu&&ar"7 %at!L7<student<cars<%a"&entSu&&ar")6s%7<C
Bforward na&eL7?uic*State&ent7 %at!L7<student<cars<?uic*State&ent)6s%7<C
B<actionC
Baction %at!L7<loans7
t"%eL7edu)'er*ele")sis)'earfacts)student)action)Student>oansAction7
sco%eL7re?uest7 +alidateL7false7 %ara&eterL7'faction7C
Bforward na&eL7direct>oan7 %at!L7<student<loans<direct>oan)6s%7<C
B<actionC
B<action-&a%%ingsC
B<struts-configC

Sa&%le A%%lication

4e?uire&ents

-le&ents in Model, View, and Controller

.se-case: .ser >ogin



Sa&%le A%%: 4e?uire&ents
A student logs in) If aut!enticated, s!e is %resented wit! &ulti%le contact-infor&ation
sets 0e)g), >ocal, /illing, Per&anent1) S!e &a" c!oose to edit an" set of infor&ation
indi+iduall", or &a" edit all t"%es at once) Certain rules &ust 'e enforced:
>ocal contact info &ust include e-&ail address
>ocal contact info &ust 'e in California
/illing contact info &ust include %ostal address
Per&anent contact info &ust include %ostal address
0etc)1

Sa&%le A%%: -le&ents in MVC
Eleents in Mo!el" in #iew" an! in Controller layers
(!e #iew la"er includes one +iew for eac! use-case wit! w!ic! t!e user will 'e %resented)
(!e Mo!el contains o'6ects re%resenting entitiesA o'6ects t!at %erfor& actionsA and re%resentation of rules to
w!ic! edited data are re?uired to confor&)
(!e Controller &a%s user re?uests to Model actions, and t!e res%onse of t!e Model to a%%ro%riate Views)
Views, Controller &a%%ings, and Model ele&ents deri+ed fro& re?uire&ents:

Sa&%le A%%: >ogin .se-case
Ue": user actionsA a%%lication actions
.ser %oints 'rowser at welco&e screen
Controller recei+es root .4> re?uest, returns elco&e +iew
.ser clic*s a 'utton to log in
Controller recei+es elco&e re?uest, %resents >ogin +iew
.ser su%%lies .ID and Password, clic*s 'utton to aut!enticate
Controller recei+es >ogin re?uest, %asses control to >ogin action in Model
Controller recei+es res%onse fro& Model 0indicates login success or failure1
Controller %resents Dis%la"Contacts or >ogin9ailure +iew, 'ased on Model
res%onse
S)))T

9ini)))

You might also like