130 such as deposit and wit hdrawal . These ent it ies share a number of common
charact erist ics: •
Behaviors •
Propert ies •
Relat ionships wit h ot her ent it ies •
Rules or policies Those business ent it ies are of course t he f oundat ion of obj ect -orient ed
design and devel opment which undoubt edl y is a key aspect in any J2EE appl icat ion devel opment .
2. Application Design Using MVC Pattern
Much discussion and conf usion have been rel ayed in t he l it erat ure about what best approaches in devel oping compl ex business web appl icat ions.
Any business appl icat ions wil l need t o incorporat e t hree primary el ement s [ Bro03] :
• User int eract ion
• Business Process
• Business Ent it ies
The st ruct ure and rel at ionship of t hese el ement s is shown in Figure 1.
Figure 1: T he St ruct ure of a Business Applicat ion
Ref erred t o a current research in IBM [ Tai04] , as web appl icat ion grow in size, it becomes more and more crit ical t o support modul ar appl icat ion
design and paral l el devel opment . It al so needs t o support t he int egrat ion of various kinds of programming t echnol ogies.
Appl ying a Model View Cont rol l er Pat t ern in J2EE Plat f orm Using St rut s Framework
Niko Ibrahim
131
2. 1. The Model View Controller Architectural Pattern
Model View Cont rol l er archit ect ural design is proj ect ed t o hel p devel opers modul arise an appl icat ion. The benef it of using t he MVC pat t ern is t hat
devel opers isol at e t he dif f erent port ions of t he appl icat ion in order t o provide great er f l exibil it y and more opport unit y f or reuse. A primary
isol at ion point is bet ween t he present at ion obj ect s and t he appl icat ion back-end obj ect s t hat manage t he dat a and business rul es. This al l ows a
user int erf ace t o have many dif f erent screens t hat can be changed t o a l arge degree wit hout impact ing t he business l ogic and dat a component s
[ Bro03] [ Tai04] [ Lef 01] .
Figure 2 shows how t he Model , t he View, and t he Cont rol l er int eract wit h one anot her in J2EE pl at f orm:
Figure 2: MVC archit ect ure f or Java applicat ions
Some of t he maj or benef it s of using t he MVC are [ Goo04] : •
Reliability: The present at ion and t ransact ion layers have clear
separat ion, which al l ows we t o change t he l ook and f eel of an appl icat ion wit hout recompil ing Model or Cont rol l er code.
•
High reuse and adaptability: The MVC let s we use mult ipl e t ypes of
views, al l accessing t he same server-side code. This incl udes anyt hing f rom Web browsers HTTP t o wirel ess browsers WAP.
•
Very low development and lifecycle costs: The MVC makes it
possibl e t o have l ower-l evel programmers devel op and maint ain t he user int erf aces.
•
Rapid deployment: Development t ime can be signif icant ly reduced,
because Cont rol l er programmers Java devel opers f ocus sol el y on t ransact ions, and View programmers HTML and JSP devel opers
f ocus sol el y on present at ion.
B R
O W
S E
R Controller
View Model
Application Server
132 •
Maintainability: The separat ion of present at ion and business logic
al so makes it easier t o maint ain and modif y a St rut s-based Web appl icat ion.
T he Model
The model encapsul at es t he f unct ional core of an appl icat ion, it s business l ogic. The goal of MVC is t o make t he model independent of t he view and
cont rol l er which t oget her f orm t he user int erf ace of t he appl icat ion. An obj ect may act as t he model f or more t han one MVC t riad at a t ime.
Since t he model must be independent , it cannot ref er t o eit her t he view or cont rol l er port ions of t he appl icat ion. The model may not hol d direct
inst ance variabl es t hat ref er t o t he view or t he cont rol l er. It passivel y suppl ies it s services and dat a t o t he ot her l ayers of t he appl icat ion [ Tai04] .
T he View
The view obt ains dat a f rom t he model and present s it t o t he user and represent s t he out put of t he appl icat ion. It general l y has f ree access t o t he
model , but shoul d not change t he st at e of t he model . Views are read onl y represent at ions of t he st at e of t he model and read dat a f rom t he model
using query met hods provided by t he model
T he Cont roller
The cont rol l er component isol at es how a user’ s act ions on t he screen are handl ed by t he appl icat ion. This al l ows f or an appl icat ion design t o f l exibl y
handl e t hings such as page navigat ion and access t o t he f unct ional it y provided by t he appl icat ion model in t he case of f orm submissions. This
al so provides an isol at ion point bet ween t he model and t he view. Because t he cont rol l er component handl es t he user request s and invokes f unct ions
on t he model as necessary, it al l ows f or a more l oosel y coupl ed f ront and back end. Int eract ion bet ween t he model and t he view is onl y t hrough an
event -based mechanism t hat inf orms t he view of changes t o t he model ’ s dat a [ Bro03] .
3. J2EE Platform