Patterns – Extended MVC for SOA

There are cases when your code base grows and the functionality and purpose of your business services and components needs to extend beyond what they were originally intended for, and just MVC may not be enough.

In this post I will try to show an extension of the MVC pattern meant to scale up and provide more separation of concerns in an enterprise system that might be composed of multiple layers / applications / components.

Here is an example of how a request can be service in a multi tier environment following a MVC like pattern with a couple of extra layers…

Extended MVC

Extended MVC

VIEW: A UI client, website, mobile, or any other requester launches a request against the app. All View Managers are exposed as web services / rest interfaces to the outside world.
VIEW: The View manager receives some data transfer object for a given operation.
CONTROLLER: The View manager delegates the data to the appropriate business service.
CONTROLLER / SERVICE: The transaction starts, the business service applies the application logic to the current request.
MODEL : The business service delegates state change in domain objects to the appropriate model manager.
MODEL : The model manager performs state change and acts as factory for domain objects if necessary.
MODEL : If the domain objects is persistent the model manager delegates persistence operations to the appropriate persistence adapter.
PERSISTENCE : The persistence adapter is specific to the technology that is being used to persist the objects, ej: database, LDAP…
MODEL: The Model manager receives Persistent Objects that may in fact be domain objects like in a hibernate based implementation.
MODEL : The model returns the domain objects to the business service.
CONTROLLER / SERVICE: The business service applies the application logic to the returned domain objects if necessary.
VIEW: The transaction ends, The View manager receives some data back from the business service as a read only facade, impeding further modification of the state.
VIEW : The view manager turns the read-only data into the appropriate view objects that are served back to the client.

And the question is… Why a couple of extra layers, can I just do all that in the controller?

In my opinion this type of architecture allows you to….

1. Scale up any layer as needed since the DTOs between layers are Serializable and you can actually partition the layers and place load balancers in between and deploy layers in different servers by converting each service layer in web services.
2. Since each service on each layer is based on an interface implementation you can deploy different view, business and persistence strategies for different clients and the same application or vice-versa.
3. Layers can be reused in different applications with different business logic.
4. All operations in your application are agnostic to the persistence mechanism used.
5. Method bodies are smaller and all parts in your app are very well structured which help you to easily navigate code without getting lost in 1000+ line methods.

The bad part is…

1. It takes you to build a couple of operations to realize that it is actually easier this way than writing long methods that do everything from constructing your objects to connect to the database and applying the right business rules.
2. Some devs think less files is better.

No, seriously, this is a pattern that I personally like for most projects but I understand in can be overkill for small things.
If you have any comments or know a better way, I’d love to hear your opinion.

An example of this pattern implemented with Java + Spring is available for download at…

svn checkout http://raulrajatutorials.googlecode.com/svn/trunk/ raulrajatutorials-read-only

Comments in the code itself should be self-explanatory if you already have some java + spring experience.

In the following pages you can see actually log output that demonstrate how the request travels through the layers and how exception handling at the view level intercepts any Throwable and turns it into the right View Object.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • RSS
  • TwitThis
  • email
  • FriendFeed
  • PDF
  • Slashdot

Pages: 1 2


This post is tagged , , ,

don't '

2 Responses

  1. dracof says:

    Que onda, quisiera ver el ejemplo de este patron, como lo descargo?

  2. Raul Raja says:

    Puedes descargarlo con:
    svn export http://raulrajatutorials.googlecode.com/svn/trunk/
    Ahi estan todos los tutoriales en svn.
    Tambien puedes ir directamente a la direccion con tu navegador

Leave a Reply

Comments may be held for moderation, please do not repost. I reserve the right to remove any inappropriate or off-topic comments. If you plan on sharing helpful code, please pass it through Postable first. Want other to know who you are? Register a Gravatar.





Sponsored Links

Categories

Pages

juice141
insurance158
gardens47
jewelers93
bestyoucanfind.info
heart146
james29
lyrics167
industries92
google142
lafayette9
kitchen229
lyrics120
jesus90
italian248
lyrics1
afreeocx.com
guide24
manhattan166
green201
information113
frank168
lyrics160
lyrics190
family142
kofflerboats.com
hitachi214
festival182
forest102
jamaica25
hotel86
executive74
guide23
flavor28
grant172
hockey221
free-microsofts.com
lyrics239
thesagamore.com
failed120
hockey220
healthbenefitsdepot.com
generic67
exchange72
fever194
island235
games21
italy249
manual188
management155
excellpressurewashers.com
library131
gibson97
grill212
marble210
flights35
hotel150
manitoba168
manual186
found137
finance231
house216
install128
institute139
lyric61
garden44
katie169
guitar51
festival181
hotels171
house189
franchise158
columbiatn.com
insurance150
guitar58
illinois22
louisville24
little204
festival189
height163
lyric67
guitar48
lyrics152
lyric48
lacrosse6
hotel154
georgia80
marine233
fitness19
cam.com
hospital62
hunter243
magazine103
floyd73
living210
sex-teen.org
lyrics46
honda22
honey36
mmgins.com
hotel142
ithaca3
lyrics202
lyrics142
management154
lyrics50
hunting247
harold105
creeksidepreserve.com
logic235
forum124
letter111
industrial90
lyrics31
gainesville242
hotel138
island224
heaters152
lyrics171
lyric69
marysvilleohio.org
gauge53
laboratories3
estate2
fields205
infant100
hairstyles77
indian72
james35
ireland214
maine125
houston231
malta148
jones128
fireplace241
honey36
rustyiron.com
finder236
germany90
jessica88
magnum119
fruit195
lyrics235
inurl204
guild36
lyrics37
kennel188
groups248
handbags91
freedom177
jeremy71
lyric81
furnace215
falls129
installing131
manufacturing203
lauderdale58
hotels176
major128
estate25
kenwood198
guitar47
hyderabad7
lyrics129
latex53
fabric103
lonsberry.com
lyrics147
maine123
sunyacc.edu
james27
veostingray.com
landing17
gallery12
lyrics231
madden90
furniture217
lyrics179
fountain146
little197
indian70
lounge27
lyrics121
keygen206
kevin201
import41
foster135
happy95
history199
jones124
kitten231
furniture236
manor170
language22
festival186
flash24
guitar43
lyrics44
homes8
hawaii119
hotel108
madden90
knight236
goneglobal35.com
florist65
myispfinder.org
lyric81
estate12
grand166
estate40
lyrics126
guitars67
fiber195
jumper148
limited160
hamilton85
female171
hospital67
instant132
estate6
glasses123
legal90
level116
pdc.org
estate18
india67
gallery13
kingdom217
florida59
katrina172
lyric76
linux183
football89
ingredients119
gymnastics73
houston229
humidifier241
naral.org
flying75
jewelry102
marine235
internet191
hotel133
hospital54
finder236
katrina172
listing193
lodge228
johnny110
mygibline.com
lyrics231
exhaust83
india54
little196
fuelmaker.com
lyrics163
harrison108
europe51
leather84
luggage33
gallery1
london242
lyrics67
magnum119
italy249
gallery3
lyrics9
london246
24fusion.info
hawaii118
lyric69
great186
thunderwear.com
market243
lyrics200
guide23
james27
linux179
houston222
example60
louisiana21
living211
maison127
californiaduihelp.com
fisher8
lyrics42
horses52
horse46
genesis68
indianapolis82
headphones123
lyrics201
forum123
local219
jelly60
malaysia144
fender177
lyric65
factory116
nomino.ca
greensboro206
express93
humidifier241
lights156
exercise76
girls104
jewish103
honda17
pulaskicountyassessor.net
lyric78
lyric75
harley103
group234
houses217
hockey219
lynch39
machine76
honda31
island229
gymnastics73
harvard114
katie168
infant100
lyrics207
language33
financialhack.com
login238
garcia35
manufacturer202
banana1015.com