Anda di halaman 1dari 32

1 lnLroducLlon

2 8ackground
3 rerequlslLes
4 1he Maln ConLenL
41 WhaL ls SofLware ArchlLecLure?
42 Why ArchlLecLure ls lmporLanL?
43 WhaL ls CC?
44 WhaL ls an Cb[ecL?
43 WhaL ls a Class?
46 Pow Lo ldenLlfy and deslgn a Class?
47 WhaL ls LncapsulaLlon (or lnformaLlon hldlng)?
48 WhaL ls AssoclaLlon?
49 WhaL ls Lhe dlfference beLween AssoclaLlon AggregaLlon and ComposlLlon?
410 WhaL ls AbsLracLlon and CenerallzaLlon?
411 WhaL ls an AbsLracL class?
412 WhaL ls an lnLerface?
413 WhaL ls Lhe dlfference beLween a Class and an lnLerface?
414 WhaL ls Lhe dlfference beLween an lnLerface and an AbsLracL class?
413 WhaL ls lmpllclL and LxpllclL lnLerface lmplemenLaLlons?
416 WhaL ls lnherlLance?
417 WhaL ls olymorphlsm?
418 WhaL ls MeLhod Cverloadlng?
419 WhaL ls CperaLor overloadlng?
420 WhaL ls MeLhod Cverrldlng?
421 WhaL ls a use case?
422 WhaL ls a Class ulagram?
423 WhaL ls a ackage ulagram?
424 WhaL ls a Sequence ulagram?
423 WhaL ls LwoLler archlLecLure?
426 WhaL ls LhreeLler archlLecLure?
427 WhaL ls MvC archlLecLure?
428 WhaL ls SCA?
429 WhaL ls Lhe uaLa Access Layer?
430 WhaL ls Lhe 8uslness Loglc Layer?
431 WhaL ls Cang of lour (Col) ueslgn aLLerns?
432 WhaL ls Lhe dlfference beLween AbsLracL lacLory and 8ullder deslgn paLLerns?
3 WhaL ls Lhe Concluslon?
6 WhaL l 8eferred?
7 PlsLory
1 lnLroducLlon
l have noLlced an lncrease ln Lhe number of arLlcles publlshed ln Lhe ArchlLecL caLegory ln codepro[ecL
durlng Lhe lasL few monLhs 1he number of readers for mosL of Lhese arLlcles ls also hlgh Lhough Lhe
raLlngs for Lhe arLlcles are noL 1hls lndlcaLes LhaL readers are lnLeresLed ln readlng arLlcles on
ArchlLecLure buL Lhe quallLy does noL maLch Lhelr expecLaLlons 1hls arLlcle ls a consLrucLlve aLLempL Lo
group/ deflne/ explaln all lnLroducLory concepLs of sofLware archlLecLure for well seasoned developers
who are looklng Lo Lake Lhelr nexL sLep as sysLem archlLecLs
Cne day l read an arLlcle LhaL sald LhaL Lhe rlchesL 2 percenL own half Lhe worlds wealLh lL also sald LhaL
Lhe rlchesL 1 percenL of adulLs owned 40 percenL of global asseLs ln Lhe year 2000 And furLher LhaL Lhe
rlchesL 10 percenL of adulLs accounLed for 83 percenL of Lhe worlds LoLal wealLh So Lhere ls an
unbalanced dlsLrlbuLlon of wealLh ln Lhe physlcal world Pave you ever LhoughL of an unbalanced
dlsLrlbuLlon of knowledge ln Lhe sofLware world? Accordlng Lo my vlew polnL Lhe masslve expanslon of
Lhe sofLware lndusLry ls forclng developers Lo use already lmplemenLed llbrarles servlces and
frameworks Lo develop sofLware wlLhln ever shorLer perlods of Llme 1he new developers are Lralned Lo
use (l would say more ofLen) already developed sofLware componenLs Lo compleLe Lhe developmenL
qulcker 1hey [usL plug ln an exlsLlng llbrary and some how manage Lo achleve Lhe requlremenLs 8uL Lhe
sad parL of Lhe sLory ls LhaL Lhey never geL a Lralnlng Lo deflne deslgn Lhe archlLecLure for and
lmplemenL such componenLs As Lhe number of years pass by Lhese developers become leads and also
sofLware archlLecLs 1helr LlLles change buL Lhe old legacy of noL undersLandlng of noL havlng any
archlLecLural experlence conLlnues creaLlng a vacuum of good archlLecLs 1he boLLom llne ls LhaL only a
small percenLage of developers know how Lo deslgn a Lruly ob[ecL orlenLed sysLem 1he soluLlon Lo Lhls
problem ls geLLlng harder every day as Lhe aggresslve naLure of Lhe sofLware lndusLry does noL supporL
an easy ad[usLmenL Lo exlsLlng processes and also Lhe relaLed onllne Leachlng maLerlals are elLher
complex or less pracLlcal or someLlmes even wrong 1he mosL of Lhem use lmpracLlcal lrrelevanL
examples of shapes anlmals and many oLher physlcal world enLlLles Lo Leach concepLs of sofLware
archlLecLure 1here are only very few good buslnessorlenLed deslgn references unforLunaLely l myself
am no excepLlon and am a resulL of Lhls very same sysLem l goL Lhe same educaLlon LhaL all of you dld
and also referred Lo Lhe same resource seL you all read
Comlng back Lo Lhe lnlLlal polnL l noLlced LhaL Lhere ls a knowledge gap lncreaslng every day beLween
Lhe archlLecLs who know how Lo archlLecL a sysLem properly and Lhe oLhers who do noL know 1he ones
who know know lL rlghL 8uL Lhe ones who do noL know know noLhlng !usL llke Lhe world's wealLh
dlsLrlbuLlon lL ls an unbalanced dlsLrlbuLlon of knowledge
2 8ackground
1hls arLlcle began afLer readlng and hearlng Lhe quesLlons new developers have on baslcs of sofLware
archlLecLure 1here are some good arLlcles ouL Lhere buL sLlll developers sLruggle Lo undersLand Lhe
baslc concepLs and more lmporLanLly Lhe way Lo apply Lhem correcLly
As l see lL newcomers wlll always sLruggle Lo undersLand a preclse deflnlLlon of a new concepL because
lL ls always a new and hence unfamlllar ldea 1he one who has experlence undersLands Lhe meanlng
buL Lhe one who doesn'L sLruggles Lo undersLand Lhe very same deflnlLlon lL ls llke LhaL Lmployers
wanL experlenced employees So Lhey say you need Lo have experlence Lo geL a [ob 8uL how Lhe hell ls
one supposed Lo have LhaL experlence lf no one ls wllllng Lo glve hlm a [ob? As ln Lhe general case Lhe
sLarL wlLh sofLware archlLecLure ls no excepLlon lL wlll be dlfflculL When you sLarL Lo deslgn your very
flrsL sysLem you wlll Lry Lo apply everyLhlng you know or learned from everywhere ?ou wlll feel LhaL an
lnLerface needs Lo be deflned for every class llke l dld once ?ou wlll flnd lL harder Lo undersLand when
and when noL Lo do someLhlng !usL prepare Lo go Lhrough a palnful process CLhers wlll crlLlclze you
may laugh aL you and say LhaL Lhe way you have deslgned lL ls wrong LlsLen Lo Lhem and learn
conLlnuously ln Lhls process you wlll also have Lo read and Lhlnk a loL l hope LhaL Lhls arLlcle wlll glve
you Lhe rlghL sLarL for LhaL long [ourney
1he knowledge of Lhe acLlons of greaL men acqulred by long experlence ln conLemporary affalrs and a
conLlnual sLudy of anLlqulLy" l read Lhls phrase when l was readlng Lhe book named 1he ArL of War"
seems appllcable here lsn'L lL?
3 rerequlslLes
1hls arLlcle ls an efforL Lo provlde an accuraLe lnformaLlon pool for new developers on Lhe baslcs of
sofLware archlLecLure focuslng on Cb[ecL CrlenLed rogrammlng (CC) lf you are a developer who has
a mlnlmum of Lhree or more years of conLlnuous developmenL experlence and has LhaL hunger Lo learn
more Lo sLepln Lo Lhe nexL level Lo become a sofLware archlLecL Lhls arLlcle ls for you
4 1he Maln ConLenL
41 WhaL ls SofLware ArchlLecLure?
SofLware ArchlLecLure ls deflned Lo be Lhe rules heurlsLlcs and paLLerns governlng
arLlLlonlng Lhe problem and Lhe sysLem Lo be bullL lnLo dlscreLe pleces
1echnlques used Lo creaLe lnLerfaces beLween Lhese pleces
1echnlques used Lo manage overall sLrucLure and flow
1echnlques used Lo lnLerface Lhe sysLem Lo lLs envlronmenL
ApproprlaLe use of developmenL and dellvery approaches Lechnlques and Lools
42 Why ArchlLecLure ls lmporLanL?

1he prlmary goal of sofLware archlLecLure ls Lo deflne Lhe nonfuncLlonal requlremenLs of a sysLem and
deflne Lhe envlronmenL 1he deLalled deslgn ls followed by a deflnlLlon of how Lo dellver Lhe funcLlonal
behavlor wlLhln Lhe archlLecLural rules ArchlLecLure ls lmporLanL because lL
ConLrols complexlLy
Lnforces besL pracLlces
Clves conslsLency and unlformlLy
lncreases predlcLablllLy
Lnables reuse
43 WhaL ls CC?
CC ls a deslgn phllosophy lL sLands for Cb[ecL CrlenLed rogrammlng Cb[ecLCrlenLed rogrammlng
(CC) uses a dlfferenL seL of programmlng languages Lhan old procedural programmlng languages (C
ascal eLc) LveryLhlng ln CC ls grouped as self susLalnable ob[ecLs Pence you galn reusablllLy by
means of four maln ob[ecLorlenLed programmlng concepLs
ln order Lo clearly undersLand Lhe ob[ecL orlenLaLlon leL's Lake your hand" as an example 1he hand"
ls a class ?our body has Lwo ob[ecLs of Lype hand named lefL hand and rlghL hand 1helr maln funcLlons
are conLrolled/ managed by a seL of elecLrlcal slgnals senL Lhrough your shoulders (Lhrough an
lnLerface) So Lhe shoulder ls an lnLerface whlch your body uses Lo lnLeracL wlLh your hands 1he hand ls
a well archlLecLed class 1he hand ls belng reused Lo creaLe Lhe lefL hand and Lhe rlghL hand by sllghLly
changlng Lhe properLles of lL
44 WhaL ls an Cb[ecL?
An ob[ecL can be consldered a Lhlng LhaL can perform a seL of relaLed acLlvlLles 1he seL of acLlvlLles
LhaL Lhe ob[ecL performs deflnes Lhe ob[ecLs behavlor lor example Lhe hand can grlp someLhlng or a
SLudenL (ob[ecL) can glve Lhe name or address
ln pure CC Lerms an ob[ecL ls an lnsLance of a class
43 WhaL ls a Class?

A class ls slmply a represenLaLlon of a Lype of ob[ecL lL ls Lhe blueprlnL/ plan/ LemplaLe LhaL descrlbe Lhe
deLalls of an ob[ecL A class ls Lhe blueprlnL from whlch Lhe lndlvldual ob[ecLs are creaLed Class ls
composed of Lhree Lhlngs a name aLLrlbuLes and operaLlons
publlc class SLudenL


Accordlng Lo Lhe sample glven below we can say LhaL Lhe sLudenL ob[ecL named ob[ecLSLudenL has
creaLed ouL of Lhe SLudenL class
SLudenL ob[ecLSLudenL new SLudenL()
ln real world youll ofLen flnd many lndlvldual ob[ecLs all of Lhe same klnd As an example Lhere may be
Lhousands of oLher blcycles ln exlsLence all of Lhe same make and model Lach blcycle has bullL from Lhe
same blueprlnL ln ob[ecLorlenLed Lerms we say LhaL Lhe blcycle ls an lnsLance of Lhe class of ob[ecLs
known as blcycles
ln Lhe sofLware world Lhough you may noL have reallzed lL you have already used classes lor example
Lhe 1exL8ox conLrol you always used ls made ouL of Lhe 1exL8ox class whlch deflnes lLs appearance
and capablllLles Lach Llme you drag a 1exL8ox conLrol you are acLually creaLlng a new lnsLance of Lhe
1exL8ox class
46 Pow Lo ldenLlfy and deslgn a Class?
1hls ls an arL each deslgner uses dlfferenL Lechnlques Lo ldenLlfy classes Powever accordlng Lo Cb[ecL
CrlenLed ueslgn rlnclples Lhere are flve prlnclples LhaL you musL follow when deslgn a class
S8 1he Slngle 8esponslblllLy rlnclple
A class should have one and only one reason Lo change
CC 1he Cpen Closed rlnclple
?ou should be able Lo exLend a classes behavlor wlLhouL modlfylng lL
LS 1he Llskov SubsLlLuLlon rlnclple
uerlved classes musL be subsLlLuLable for Lhelr base classes
ul 1he uependency lnverslon rlnclple
uepend on absLracLlons noL on concreLlons
lS 1he lnLerface SegregaLlon rlnclple
Make flne gralned lnLerfaces LhaL are cllenL speclflc
lor more lnformaLlon on deslgn prlnclples please refer Lo Cb[ecL MenLor
AddlLlonally Lo ldenLlfy a class correcLly you need Lo ldenLlfy Lhe full llsL of leaf level funcLlons/
operaLlons of Lhe sysLem (granular level use cases of Lhe sysLem) 1hen you can proceed Lo group each
funcLlon Lo form classes (classes wlll group same Lypes of funcLlons/ operaLlons) Powever a well
deflned class musL be a meanlngful grouplng of a seL of funcLlons and should supporL Lhe reusablllLy
whlle lncreaslng expandablllLy/ malnLalnablllLy of Lhe overall sysLem
ln sofLware world Lhe concepL of dlvldlng and conquerlng ls always recommended lf you sLarL analyzlng
a full sysLem aL Lhe sLarL you wlll flnd lL harder Lo manage So Lhe beLLer approach ls Lo ldenLlfy Lhe
module of Lhe sysLem flrsL and Lhen dlg deep ln Lo each module separaLely Lo seek ouL classes
A sofLware sysLem may conslsL of many classes 8uL ln any case when you have many lL needs Lo be
managed 1hlnk of a blg organlzaLlon wlLh lLs work force exceedlng several Lhousand employees (leL's
Lake one employee as a one class) ln order Lo manage such a work force you need Lo have proper
managemenL pollcles ln place Same Lechnlque can be applles Lo manage classes of your sofLware
sysLem as well ln order Lo manage Lhe classes of a sofLware sysLem and Lo reduce Lhe complexlLy Lhe
sysLem deslgners use several Lechnlques whlch can be grouped under four maln concepLs named
LncapsulaLlon AbsLracLlon lnherlLance and olymorphlsm 1hese concepLs are Lhe four maln gods of
CC world and ln sofLware Lerm Lhey are called four maln Cb[ecL CrlenLed rogrammlng (CC)
ConcepLs
47 WhaL ls LncapsulaLlon (or lnformaLlon hldlng)?
1he encapsulaLlon ls Lhe lncluslon wlLhln a program ob[ecL of all Lhe resources need for Lhe ob[ecL Lo
funcLlon baslcally Lhe meLhods and Lhe daLa ln CC Lhe encapsulaLlon ls malnly achleved by creaLlng
classes Lhe classes expose publlc meLhods and properLles 1he class ls klnd of a conLalner or capsule or a
cell whlch encapsulaLe Lhe seL of meLhods aLLrlbuLe and properLles Lo provlde lLs lndenLed
funcLlonallLles Lo oLher classes ln LhaL sense encapsulaLlon also allows a class Lo change lLs lnLernal
lmplemenLaLlon wlLhouL hurLlng Lhe overall funcLlonlng of Lhe sysLem 1haL ldea of encapsulaLlon ls Lo
hlde how a class does lL buL Lo allow requesLlng whaL Lo do

ln order Lo modularlze/ deflne Lhe funcLlonallLy of a one class LhaL class can uses funcLlons/ properLles
exposed by anoLher class ln many dlfferenL ways Accordlng Lo Cb[ecL CrlenLed rogrammlng Lhere are
several Lechnlques classes can use Lo llnk wlLh each oLher and Lhey are named assoclaLlon aggregaLlon
and composlLlon
1here are several oLher ways LhaL an encapsulaLlon can be used as an example we can Lake Lhe usage of
an lnLerface 1he lnLerface can be used Lo hlde Lhe lnformaLlon of an lmplemenLed class
lSLudenL mySLudenL new LocalSLudenL()
lSLudenL mySLudenL new lorelgnSLudenL()
Accordlng Lo Lhe sample above (leL's assume LhaL LocalSLudenL and lorelgnSLudenL are lmplemenLed by
Lhe lSLudenL lnLerface) we can see how LocalSLudenL and lorelgnSLudenL are hldlng Lhelr locallze
lmplemenLlng lnformaLlon Lhrough Lhe lSLudenL lnLerface
48 WhaL ls AssoclaLlon?
AssoclaLlon ls a (*a*) relaLlonshlp beLween Lwo classes lL allows one ob[ecL lnsLance Lo cause anoLher Lo
perform an acLlon on lLs behalf AssoclaLlon ls Lhe more general Lerm LhaL deflne Lhe relaLlonshlp
beLween Lwo classes where as Lhe aggregaLlon and composlLlon are relaLlvely speclal
publlc class SLudenL8eglsLrar

publlc SLudenL8eglsLrar ()

new 8ecordManager()lnlLlallze()


ln Lhls case we can say LhaL Lhere ls an assoclaLlon beLween SLudenL8eglsLrar and 8ecordManager or
Lhere ls a dlrecLlonal assoclaLlon from SLudenL8eglsLrar Lo 8ecordManager or SLudenL 8eglsLrar use a
(*use*) 8ecordManager Slnce a dlrecLlon ls expllclLly speclfled ln Lhls case Lhe conLroller class ls Lhe
SLudenL8eglsLrar

1o some beglnners assoclaLlon ls a confuslng concepL 1he Lroubles creaLed noL only by Lhe assoclaLlon
alone buL wlLh Lwo oLher CC concepLs LhaL ls assoclaLlon aggregaLlon and composlLlon Lveryone
undersLands assoclaLlon before aggregaLlon and composlLlon are descrlbed 1he aggregaLlon or
composlLlon cannoL be separaLely undersLood lf you undersLand Lhe aggregaLlon alone lL wlll crack Lhe
deflnlLlon glven for assoclaLlon and lf you Lry Lo undersLand Lhe composlLlon alone lL wlll always
LhreaLen Lhe deflnlLlon glven for aggregaLlon all Lhree concepLs are closely relaLed hence musL sLudy
LogeLher by comparlng one deflnlLlon Lo anoLher LeL's explore all Lhree and see wheLher we can
undersLand Lhe dlfferences beLween Lhese useful concepLs
49 WhaL ls Lhe dlfference beLween AssoclaLlon AggregaLlon and ComposlLlon?
AssoclaLlon ls a (*a*) relaLlonshlp beLween Lwo classes where one class use anoLher 8uL aggregaLlon
descrlbes a speclal Lype of an assoclaLlon AggregaLlon ls Lhe (*Lhe*) relaLlonshlp beLween Lwo classes
When ob[ecL of one class has an (*has*) ob[ecL of anoLher lf second ls a parL of flrsL (conLalnmenL
relaLlonshlp) Lhen we called LhaL Lhere ls an aggregaLlon beLween Lwo classes unllke assoclaLlon
aggregaLlon always lnslsLs a dlrecLlon
publlc class unlverslLy

prlvaLe Chancellor unlverslLyChancellor new Chancellor()


ln Lhls case l can say LhaL unlverslLy aggregaLe Chancellor or unlverslLy has an (*hasa*) Chancellor 8uL
even wlLhouL a Chancellor a unlverslLy can exlsLs 8uL Lhe laculLles cannoL exlsL wlLhouL Lhe unlverslLy
Lhe llfe Llme of a laculLy (or laculLles) aLLached wlLh Lhe llfe Llme of Lhe unlverslLy lf unlverslLy ls
dlsposed Lhe laculLles wlll noL exlsL ln LhaL case we called LhaL unlverslLy ls composed of laculLles So
LhaL composlLlon can be recognlzed as a speclal Lype of an aggregaLlon

Same way as anoLher example you can say LhaL Lhere ls a composlLe relaLlonshlp lnbeLween a
keyvaluealrCollecLlon and a keyvaluealr 1he Lwo muLually depend on each oLher
neL and !ava uses Lhe ComposlLe relaLlon Lo deflne Lhelr CollecLlons l have seen ComposlLlon ls belng
used ln many oLher ways Loo Powever Lhe more lmporLanL facLor LhaL mosL people forgeL ls Lhe llfe
Llme facLor 1he llfe Llme of Lhe Lwo classes LhaL has bond wlLh a composlLe relaLlon muLually depend on
each oLher lf you Lake Lhe neL CollecLlon Lo undersLand Lhls Lhere you have Lhe CollecLlon LlemenL
deflne lnslde (lL ls an lnner parL hence called lL ls composed of) Lhe CollecLlon farclng Lhe LlemenL Lo
geL dlsposed wlLh Lhe CollecLlon lf noL as an example lf you deflne Lhe CollecLlon and lL's LlemenL Lo be
lndependenL Lhen Lhe relaLlonshlp would be more of a Lype AggregaLlon Lhan a ComposlLlon So Lhe
polnL ls lf you wanL Lo blnd Lwo classes wlLh ComposlLe relaLlon more accuraLe way ls Lo have a one
deflne lnslde Lhe oLher class (maklng lL a proLecLed or prlvaLe class) 1hls way you are allowlng Lhe ouLer
class Lo fulflll lLs purpose whlle Lylng Lhe llfeLlme of Lhe lnner class wlLh Lhe ouLer class
So ln summary we can say LhaL aggregaLlon ls a speclal klnd of an assoclaLlon and composlLlon ls a
speclal klnd of an aggregaLlon (AssoclaLlonAggregaLlonComposlLlon)

410 WhaL ls AbsLracLlon and CenerallzaLlon?
AbsLracLlon ls an emphasls on Lhe ldea quallLles and properLles raLher Lhan Lhe parLlculars (a
suppresslon of deLall) 1he lmporLance of absLracLlon ls derlved from lLs ablllLy Lo hlde lrrelevanL deLalls
and from Lhe use of names Lo reference ob[ecLs AbsLracLlon ls essenLlal ln Lhe consLrucLlon of programs
lL places Lhe emphasls on whaL an ob[ecL ls or does raLher Lhan how lL ls represenLed or how lL works
1hus lL ls Lhe prlmary means of managlng complexlLy ln large programs
Whlle absLracLlon reduces complexlLy by hldlng lrrelevanL deLall generallzaLlon reduces complexlLy by
replaclng mulLlple enLlLles whlch perform slmllar funcLlons wlLh a slngle consLrucL CenerallzaLlon ls Lhe
broadenlng of appllcaLlon Lo encompass a larger domaln of ob[ecLs of Lhe same or dlfferenL Lype
rogrammlng languages provlde generallzaLlon Lhrough varlables parameLerlzaLlon generlcs and
polymorphlsm lL places Lhe emphasls on Lhe slmllarlLles beLween ob[ecLs 1hus lL helps Lo manage
complexlLy by collecLlng lndlvlduals lnLo groups and provldlng a represenLaLlve whlch can be used Lo
speclfy any lndlvldual of Lhe group
AbsLracLlon and generallzaLlon are ofLen used LogeLher AbsLracLs are generallzed Lhrough
parameLerlzaLlon Lo provlde greaLer uLlllLy ln parameLerlzaLlon one or more parLs of an enLlLy are
replaced wlLh a name whlch ls new Lo Lhe enLlLy 1he name ls used as a parameLer When Lhe
parameLerlzed absLracL ls lnvoked lL ls lnvoked wlLh a blndlng of Lhe parameLer Lo an argumenL
411 WhaL ls an AbsLracL class?
AbsLracL classes whlch declared wlLh Lhe absLracL keyword cannoL be lnsLanLlaLed lL can only be used
as a superclass for oLher classes LhaL exLend Lhe absLracL class AbsLracL class ls Lhe concepL and
lmplemenLaLlon geLs compleLed when lL ls belng reallzed by a subclass ln addlLlon Lo Lhls a class can
lnherlL only from one absLracL class (buL a class may lmplemenL many lnLerfaces) and musL overrlde all
lLs absLracL meLhods/ properLles and may overrlde vlrLual meLhods/ properLles
AbsLracL classes are ldeal when lmplemenLlng frameworks As an example leL's sLudy Lhe absLracL class
named Logger8ase below lease carefully read Lhe commenLs as lL wlll help you Lo undersLand Lhe
reasonlng behlnd Lhls code
publlc absLracL class Logger8ase

/// summary
/// fleld ls prlvaLe so lL lnLend Lo use lnslde Lhe class only
/// /summary
prlvaLe log4neLlLog logger null

/// summary
/// proLecLed so lL only vlslble for lnherlLed class
/// /summary
proLecLed Logger8ase()

// 1he prlvaLe ob[ecL ls creaLed lnslde Lhe consLrucLor
logger log4neLLogManagerCeLLogger(LhlsLogreflx)
// 1he addlLlonal lnlLlallzaLlon ls done lmmedlaLely afLer
log4neLConflguCMConflguraLorConflgure()


/// summary
/// When you deflne Lhe properLy as absLracL
/// lL forces Lhe lnherlLed class Lo overrlde Lhe Logreflx
/// So wlLh Lhe help of Lhls Lechnlque Lhe log can be made
/// lnslde Lhe absLracL class lLself lrrespecLlve of lL orlgln
/// lf you sLudy carefully you wlll flnd a reason for noL Lo have seL" meLhod here
/// /summary
proLecLed absLracL SysLem1ype Logreflx

geL


/// summary
/// Slmple log meLhod
/// whlch ls only vlslble for lnherlLed classes
/// /summary
/// param namemessage/param
proLecLed vold LogLrror(sLrlng message)

lf (LhlsloggerlsLrrorLnabled)

LhlsloggerLrror(message)



/// summary
/// ubllc properLles whlch exposes Lo lnherlLed class
/// and all oLher classes LhaL have access Lo lnherlLed class
/// /summary
publlc bool ls1hlsLogLrror

geL

reLurn LhlsloggerlsLrrorLnabled



1he ldea of havlng Lhls class as an absLracL ls Lo deflne a framework for excepLlon logglng 1hls class wlll
allow all subclass Lo galn access Lo a common excepLlon logglng module and wlll faclllLaLe Lo easlly
replace Lhe logglng llbrary 8y Lhe Llme you deflne Lhe Logger8ase you wouldn'L have an ldea abouL
oLher modules of Lhe sysLem 8uL you do have a concepL ln mlnd and LhaL ls lf a class ls golng Lo log an
excepLlon Lhey have Lo lnherlL Lhe Logger8ase ln oLher word Lhe Logger8ase provlde a framework for
excepLlon logglng
LeL's Lry Lo undersLand each llne of Lhe above code
Llke any oLher class an absLracL class can conLaln flelds hence l used a prlvaLe fleld named logger
declare Lhe lLog lnLerface of Lhe famous log4neL llbrary 1hls wlll allow Lhe Loggerbase class Lo conLrol
whaL Lo use for logglng hence wlll allow changlng Lhe source logger llbrary easlly
1he access modlfler of Lhe consLrucLor of Lhe Logger8ase ls proLecLed 1he publlc consLrucLor has no use
when Lhe class ls of Lype absLracL 1he absLracL classes are noL allowed Lo lnsLanLlaLe Lhe class So l wenL
for Lhe proLecLed consLrucLor
1he absLracL properLy named Logreflx ls an lmporLanL one lL enforces and guaranLees Lo have a value
for Logreflx (Logreflx uses Lo obLaln Lhe deLall of Lhe source class whlch Lhe excepLlon has occurred)
for every subclass before Lhey lnvoke a meLhod Lo log an error
1he meLhod named LogLrror ls proLecLed hence exposed Lo all subclasses ?ou are noL allowed or
raLher you cannoL make lL publlc as any class wlLhouL lnherlLlng Lhe Logger8ase cannoL use lL
meanlngfully
LeL's flnd ouL why Lhe properLy named ls1hlsLogLrror ls publlc lL may be lmporLanL/ useful for oLher
assoclaLed classes of an lnherlLed class Lo know wheLher Lhe assoclaLed member logs lLs errors or noL
AparL from Lhese you can also have vlrLual meLhods deflned ln an absLracL class 1he vlrLual meLhod may
have lLs defaulL lmplemenLaLlon where a subclass can overrlde lL when requlred
All and all Lhe lmporLanL facLor here ls LhaL all CC concepLs should be used carefully wlLh reasons you
should be able Lo loglcally explaln why you make a properLy a publlc or a fleld a prlvaLe or a class an
absLracL AddlLlonally when archlLecLlng frameworks Lhe CC concepLs can be used Lo forcefully gulde
Lhe sysLem Lo be developed ln Lhe way framework archlLecL's wanLed lL Lo be archlLecLed lnlLlally
412 WhaL ls an lnLerface?
ln summary Lhe lnLerface separaLes Lhe lmplemenLaLlon and deflnes Lhe sLrucLure and Lhls concepL ls
very useful ln cases where you need Lhe lmplemenLaLlon Lo be lnLerchangeable AparL from LhaL an
lnLerface ls very useful when Lhe lmplemenLaLlon changes frequenLly Some say you should deflne all
classes ln Lerms of lnLerfaces buL l Lhlnk recommendaLlon seems a blL exLreme
lnLerface can be used Lo deflne a generlc LemplaLe and Lhen one or more absLracL classes Lo deflne
parLlal lmplemenLaLlons of Lhe lnLerface lnLerfaces [usL speclfy Lhe meLhod declaraLlon (lmpllclLly publlc
and absLracL) and can conLaln properLles (whlch are also lmpllclLly publlc and absLracL) lnLerface
deflnlLlon beglns wlLh Lhe keyword lnLerface An lnLerface llke LhaL of an absLracL class cannoL be
lnsLanLlaLed
lf a class LhaL lmplemenLs an lnLerface does noL deflne all Lhe meLhods of Lhe lnLerface Lhen lL musL be
declared absLracL and Lhe meLhod deflnlLlons musL be provlded by Lhe subclass LhaL exLends Lhe
absLracL class ln addlLlon Lo Lhls an lnLerfaces can lnherlL oLher lnLerfaces
1he sample below wlll provlde an lnLerface for our Logger8ase absLracL class
Collapse | Copy Code
publlc lnLerface lLogger

bool ls1hlsLogLrror geL

413 WhaL ls Lhe dlfference beLween a Class and an lnLerface?
ln neL/ C# a class can be deflned Lo lmplemenL an lnLerface and also lL supporLs mulLlple
lmplemenLaLlons When a class lmplemenLs an lnLerface an ob[ecL of such class can be encapsulaLed
lnslde an lnLerface
lf MyLogger ls a class whlch lmplemenLs lLogger Lhere we can wrlLe
lLogger log new MyLogger()
A class and an lnLerface are Lwo dlfferenL Lypes (concepLually) 1heoreLlcally a class emphasls Lhe ldea of
encapsulaLlon whlle an lnLerface emphasls Lhe ldea of absLracLlon (by suppresslng Lhe deLalls of Lhe
lmplemenLaLlon) 1he Lwo poses a clear separaLlon from one Lo anoLher 1herefore lL ls very dlfflculL or
raLher lmposslble Lo have an effecLlve meanlngful comparlson beLween Lhe Lwo buL lL ls very useful and
also meanlngful Lo have a comparlson beLween an lnLerface and an absLracL class
414 WhaL ls Lhe dlfference beLween an lnLerface and an AbsLracL class?
1here are qulLe a blg dlfference beLween an lnLerface and an absLracL class even Lhough boLh look
slmllar
lnLerface deflnlLlon beglns wlLh a keyword lnLerface so lL ls of Lype lnLerface
AbsLracL classes are declared wlLh Lhe absLracL keyword so lL ls of Lype class
lnLerface has no lmplemenLaLlon buL Lhey have Lo be lmplemenLed
AbsLracL class's meLhods can have lmplemenLaLlons and Lhey have Lo be exLended
lnLerfaces can only have meLhod declaraLlon (lmpllclLly publlc and absLracL) and flelds (lmpllclLly publlc
sLaLlc)
AbsLracL class's meLhods can'L have lmplemenLaLlon only when declared absLracL
lnLerface can lnherlL more Lhan one lnLerfaces
AbsLracL class can lmplemenL more Lhan one lnLerfaces buL can lnherlL only one class
AbsLracL class musL overrlde all absLracL meLhod and may overrlde vlrLual meLhods
lnLerface can be used when Lhe lmplemenLaLlon ls changlng
AbsLracL class can be used Lo provlde some defaulL behavlor for a base class
lnLerface makes lmplemenLaLlon lnLerchangeable
lnLerface lncrease securlLy by hldlng Lhe lmplemenLaLlon
AbsLracL class can be used when lmplemenLlng framework
AbsLracL classes are an excellenL way Lo creaLe planned lnherlLance hlerarchles and also Lo use as non
leaf classes ln class hlerarchles
AbsLracL classes leL you deflne some behavlors Lhey force your subclasses Lo provlde oLhers lor
example lf you have an appllcaLlon framework an absLracL class can be used Lo provlde Lhe defaulL
lmplemenLaLlon of Lhe servlces and all mandaLory modules such as evenL logglng and message handllng
eLc 1hls approach allows Lhe developers Lo develop Lhe appllcaLlon wlLhln Lhe gulded help provlded by
Lhe framework
Powever ln pracLlce when you come across wlLh some appllcaLlonspeclflc funcLlonallLy LhaL only your
appllcaLlon can perform such as sLarLup and shuLdown Lasks eLc 1he absLracL base class can declare
vlrLual shuLdown and sLarLup meLhods 1he base class knows LhaL lL needs Lhose meLhods buL an
absLracL class leLs your class admlL LhaL lL doesnL know how Lo perform Lhose acLlons lL only knows LhaL
lL musL lnlLlaLe Lhe acLlons When lL ls Llme Lo sLarL up Lhe absLracL class can call Lhe sLarLup meLhod
When Lhe base class calls Lhls meLhod lL can execuLe Lhe meLhod deflned by Lhe chlld class
413 WhaL ls lmpllclL and LxpllclL lnLerface lmplemenLaLlons?
As menLloned before neL supporL mulLlple lmplemenLaLlons Lhe concepL of lmpllclL and expllclL
lmplemenLaLlon provlde safe way Lo lmplemenL meLhods of mulLlple lnLerfaces by hldlng exposlng or
preservlng ldenLlLles of each of lnLerface meLhods even when Lhe meLhod slgnaLures are Lhe same
LeLs conslder Lhe lnLerfaces deflned below
lnLerface lulsposable

vold ulspose()

Pere you can see LhaL Lhe class SLudenL has lmpllclLly and expllclLly lmplemenLed Lhe meLhod named
ulspose() vla ulspose and lulsposableulspose
class SLudenL lulsposable

publlc vold ulspose()

ConsoleWrlLeLlne(SLudenLulspose)


vold lulsposableulspose()

ConsoleWrlLeLlne(lulsposableulspose)


416 WhaL ls lnherlLance?
AblllLy of a new class Lo be creaLed from an exlsLlng class by exLendlng lL ls called lnherlLance

publlc class LxcepLlon




publlc class lCLxcepLlon LxcepLlon


Accordlng Lo Lhe above example Lhe new class (lCLxcepLlon) whlch ls called Lhe derlved class or
subclass lnherlLs Lhe members of an exlsLlng class (LxcepLlon) whlch ls called Lhe base class or super
class 1he class lCLxcepLlon can exLend Lhe funcLlonallLy of Lhe class LxcepLlon by addlng new Lypes and
meLhods and by overrldlng exlsLlng ones
!usL llke absLracLlon ls closely relaLed wlLh generallzaLlon Lhe lnherlLance ls closely relaLed wlLh
speclallzaLlon lL ls lmporLanL Lo dlscuss Lhose Lwo concepLs LogeLher wlLh generallzaLlon Lo beLLer
undersLand and Lo reduce Lhe complexlLy
Cne of Lhe mosL lmporLanL relaLlonshlps among ob[ecLs ln Lhe real world ls speclallzaLlon whlch can be
descrlbed as Lhe lsa" relaLlonshlp When we say LhaL a dog ls a mammal we mean LhaL Lhe dog ls a
speclallzed klnd of mammal lL has all Lhe characLerlsLlcs of any mammal (lL bears llve young nurses wlLh
mllk has halr) buL lL speclallzes Lhese characLerlsLlcs Lo Lhe famlllar characLerlsLlcs of canls domesLlcus
A caL ls also a mammal As such we expecL lL Lo share cerLaln characLerlsLlcs wlLh Lhe dog LhaL are
generallzed ln Mammal buL Lo dlffer ln Lhose characLerlsLlcs LhaL are speclallzed ln caLs
1he speclallzaLlon and generallzaLlon relaLlonshlps are boLh reclprocal and hlerarchlcal SpeclallzaLlon ls
[usL Lhe oLher slde of Lhe generallzaLlon coln Mammal generallzes whaL ls common beLween dogs and
caLs and dogs and caLs speclallze mammals Lo Lhelr own speclflc subLypes
Slmllarly as an example you can say LhaL boLh lCLxcepLlon and SecurlLyLxcepLlon are of Lype LxcepLlon
1hey have all characLerlsLlcs and behavlors of an LxcepLlon 1haL mean Lhe lCLxcepLlon ls a speclallzed
klnd of LxcepLlon A SecurlLyLxcepLlon ls also an LxcepLlon As such we expecL lL Lo share cerLaln
characLerlsLlc wlLh lCLxcepLlon LhaL are generallzed ln LxcepLlon buL Lo dlffer ln Lhose characLerlsLlcs
LhaL are speclallzed ln SecurlLyLxcepLlons ln oLher words LxcepLlon generallzes Lhe shared
characLerlsLlcs of boLh lCLxcepLlon and SecurlLyLxcepLlon whlle lCLxcepLlon and SecurlLyLxcepLlon
speclallze wlLh Lhelr characLerlsLlcs and behavlors
ln CC Lhe speclallzaLlon relaLlonshlp ls lmplemenLed uslng Lhe prlnclple called lnherlLance 1hls ls Lhe
mosL common and mosL naLural and wldely accepLed way of lmplemenL Lhls relaLlonshlp
417 WhaL ls olymorphlsms?
olymorphlsms ls a generlc Lerm LhaL means many shapes More preclsely olymorphlsms means Lhe
ablllLy Lo requesL LhaL Lhe same operaLlons be performed by a wlde range of dlfferenL Lypes of Lhlngs
AL Llmes l used Lo Lhlnk LhaL undersLandlng Cb[ecL CrlenLed rogrammlng concepLs have made lL
dlfflculL slnce Lhey have grouped under four maln concepLs whlle each concepL ls closely relaLed wlLh
one anoLher Pence one has Lo be exLremely careful Lo correcLly undersLand each concepL separaLely
whlle undersLandlng Lhe way each relaLed wlLh oLher concepLs
ln CC Lhe polymorphlsms ls achleved by uslng many dlfferenL Lechnlques named meLhod overloadlng
operaLor overloadlng and meLhod overrldlng
418 WhaL ls MeLhod Cverloadlng?
1he meLhod overloadlng ls Lhe ablllLy Lo deflne several meLhods all wlLh Lhe same name
publlc class MyLogger

publlc vold LogLrror(LxcepLlon e)

// lmplemenLaLlon goes here


publlc bool LogLrror(LxcepLlon e sLrlng message)

// lmplemenLaLlon goes here


419 WhaL ls CperaLor Cverloadlng?
1he operaLor overloadlng (less commonly known as adhoc polymorphlsms) ls a speclflc case of
polymorphlsms ln whlch some or all of operaLors llke + or are LreaLed as polymorphlc funcLlons and
as such have dlfferenL behavlors dependlng on Lhe Lypes of lLs argumenLs
publlc class Complex

prlvaLe lnL real
publlc lnL 8eal
geL reLurn real

prlvaLe lnL lmaglnary
publlc lnL lmaglnary
geL reLurn lmaglnary

publlc Complex(lnL real lnL lmaglnary)

Lhlsreal real
Lhlslmaglnary lmaglnary


publlc sLaLlc Complex operaLor +(Complex c1 Complex c2)

reLurn new Complex(c18eal + c28eal c1lmaglnary + c2lmaglnary)


l above example l have overloaded Lhe plus operaLor for addlng Lwo complex numbers 1here Lhe Lwo
properLles named 8eal and lmaglnary has been declared exposlng only Lhe requlred geL" meLhod whlle
Lhe ob[ecL's consLrucLor ls demandlng for mandaLory real and lmaglnary values wlLh Lhe user deflned
consLrucLor of Lhe class
420 WhaL ls MeLhod Cverrldlng?
MeLhod overrldlng ls a language feaLure LhaL allows a subclass Lo overrlde a speclflc lmplemenLaLlon of a
meLhod LhaL ls already provlded by one of lLs superclasses
A subclass can glve lLs own deflnlLlon of meLhods buL need Lo have Lhe same slgnaLure as Lhe meLhod ln
lLs superclass 1hls means LhaL when overrldlng a meLhod Lhe subclasss meLhod has Lo have Lhe same
name and parameLer llsL as Lhe superclasss overrldden meLhod
uslng SysLem
publlc class Complex

prlvaLe lnL real
publlc lnL 8eal
geL reLurn real

prlvaLe lnL lmaglnary
publlc lnL lmaglnary
geL reLurn lmaglnary

publlc Complex(lnL real lnL lmaglnary)

Lhlsreal real
Lhlslmaglnary lmaglnary


publlc sLaLlc Complex operaLor +(Complex c1 Complex c2)

reLurn new Complex(c18eal + c28eal c1lmaglnary + c2lmaglnary)


publlc overrlde sLrlng 1oSLrlng()

reLurn (SLrlnglormaL(0 + 1l real lmaglnary))


ln above example l have exLended Lhe lmplemenLaLlon of Lhe sample Complex class glven under
operaLor overloadlng secLlon 1hls class has one overrldden meLhod named 1oSLrlng" whlch overrlde
Lhe defaulL lmplemenLaLlon of Lhe sLandard 1oSLrlng" meLhod Lo supporL Lhe correcL sLrlng converslon
of a complex number
Complex num1 new Complex(3 7)
Complex num2 new Complex(3 8)

// Add Lwo Complex numbers uslng Lhe
// overloaded plus operaLor
Complex sum num1 + num2

// rlnL Lhe numbers and Lhe sum
// uslng Lhe overrlden 1oSLrlng meLhod
ConsoleWrlLeLlne((0) + (1) 2 num1 num2 sum)
Console8eadLlne()
421 WhaL ls a use case?
A use case ls a Lhlng an acLor percelves from Lhe sysLem A use case maps acLors wlLh funcLlons
lmporLanLly Lhe acLors need noL be people As an example a sysLem can perform Lhe role of an acLor
when lL communlcaLe wlLh anoLher sysLem

ln anoLher angle a use case encodes a Lyplcal user lnLeracLlon wlLh Lhe sysLem ln parLlcular lL
CapLures some uservlslble funcLlon
Achleves some concreLe goal for Lhe user
A compleLe seL of use cases largely deflnes Lhe requlremenLs for your sysLem everyLhlng Lhe user can
see and would llke Lo do 1he below dlagram conLalns a seL of use cases LhaL descrlbes a slmple logln
module of a gamlng webslLe

422 WhaL ls a Class ulagram?
A class dlagrams are wldely used Lo descrlbe Lhe Lypes of ob[ecLs ln a sysLem and Lhelr relaLlonshlps
Class dlagrams model class sLrucLure and conLenLs uslng deslgn elemenLs such as classes packages and
ob[ecLs Class dlagrams descrlbe Lhree dlfferenL perspecLlves when deslgnlng a sysLem concepLual
speclflcaLlon and lmplemenLaLlon 1hese perspecLlves become evldenL as Lhe dlagram ls creaLed and
help solldlfy Lhe deslgn
1he Class dlagrams physlcal daLa models along wlLh Lhe sysLem overvlew dlagram are ln my oplnlon Lhe
mosL lmporLanL dlagrams LhaL sulLe Lhe currenL day rapld appllcaLlon developmenL requlremenLs
uML noLaLlons

423 WhaL ls a ackage ulagram?
ackage dlagrams are used Lo reflecL Lhe organlzaLlon of packages and Lhelr elemenLs When used Lo
represenL class elemenLs package dlagrams provlde a vlsuallzaLlon of Lhe namespaces ln my deslgns l
use Lhe package dlagrams Lo organlze classes ln Lo dlfferenL modules of Lhe sysLem
424 WhaL ls a Sequence ulagram?
A sequence dlagrams model Lhe flow of loglc wlLhln a sysLem ln a vlsual manner lL enable boLh Lo
documenL and valldaLe your loglc and are used for boLh analysls and deslgn purposes Sequence
dlagrams are Lhe mosL popular uML arLlfacL for dynamlc modellng whlch focuses on ldenLlfylng Lhe
behavlor wlLhln your sysLem
423 WhaL ls LwoLler archlLecLure?
1he LwoLler archlLecLure ls refers Lo cllenL/ server archlLecLures as well Lhe Lerm cllenL/ server was flrsL
used ln Lhe 1980s ln reference Lo personal compuLers (Cs) on a neLwork 1he acLual cllenL/ server
model sLarLed galnlng accepLance ln Lhe laLe 1980s and laLer lL was adapLed Lo World Wlde Web
programmlng
Accordlng Lo Lhe modern days use of LwoLler archlLecLure Lhe user lnLerfaces (or wlLh ASnL1 all web
pages) runs on Lhe cllenL and Lhe daLabase ls sLored on Lhe server 1he acLual appllcaLlon loglc can run
on elLher Lhe cllenL or Lhe server So ln Lhls case Lhe user lnLerfaces are dlrecLly access Lhe daLabase
1hose can also be nonlnLerface processlng englnes whlch provlde soluLlons Lo oLher remoLe/ local
sysLems ln elLher case Loday Lhe LwoLler model ls noL as repuLed as Lhe LhreeLler model 1he
advanLage of Lhe LwoLler deslgn ls lLs slmpllclLy buL Lhe slmpllclLy comes wlLh Lhe cosL of scalablllLy 1he
newer LhreeLler archlLecLure whlch ls more famous lnLroduces a mlddle Ller for Lhe appllcaLlon loglc

426 WhaL ls LhreeLler archlLecLure?
1he Lhree Ller sofLware archlLecLure (also known as Lhree layer archlLecLures) emerged ln Lhe 1990s Lo
overcome Lhe llmlLaLlons of Lhe Lwo Ller archlLecLure 1hls archlLecLure has aggresslvely cusLomlzed and
adopLed by modern day sysLem deslgner Lo web sysLems
1hreeLler ls a cllenLserver archlLecLure ln whlch Lhe user lnLerface funcLlonal process loglc daLa
sLorage and daLa access are developed and malnLalned as lndependenL modules some Llme on separaLe
plaLforms 1he Lerm LhreeLler or Lhreelayer as well as Lhe concepL of mulLlLler archlLecLures
(ofLen refers Lo as LhreeLler archlLecLure) seems Lo have orlglnaLed wlLhln 8aLlonal SofLware

1he 31ler archlLecLure has Lhe followlng Lhree Llers
resenLaLlon 1ler or Web Server user lnLerface dlsplaylng/ accepLlng daLa/ lnpuL Lo/ from Lhe user
AppllcaLlon Loglc/ 8uslness Loglc/ 1ransacLlon 1ler or AppllcaLlon Server uaLa valldaLlon accepLablllLy
check before belng added Lo Lhe daLabase and all oLher buslness/ appllcaLlon speclflc operaLlons
uaLa 1ler or uaLabase server Slmple readlng and wrlLlng meLhod Lo daLabase or any oLher sLorage
connecLlon command sLored procedures eLc
427 WhaL ls MvC archlLecLure?
1he ModelvlewConLroller (MvC) archlLecLure separaLes Lhe modellng of Lhe domaln Lhe presenLaLlon
and Lhe acLlons based on user lnpuL lnLo Lhree separaLe classes
unforLunaLely Lhe popularlLy of Lhls paLLern has resulLed ln a number of faulLy usages each Lechnology
(!ava ASnL1 eLc) has deflned lL ln Lhelr own way maklng lL dlfflculL Lo undersLand ln parLlcular Lhe
Lerm conLroller has been used Lo mean dlfferenL Lhlngs ln dlfferenL conLexLs 1he deflnlLlons glven
bellow are Lhe closes posslble ones l found for ASnL1 verslon of MvC

Model uaLaseL and Lyped uaLaSeL (some Llmes buslness ob[ecL ob[ecL collecLlon xML eLc) are Lhe mosL
common use of Lhe model
vlew 1he ASx and ASCx flles generally handle Lhe responslblllLles of Lhe vlew
ConLrollers 1he handllng of evenLs or Lhe conLrolllng ls usually done ln Lhe codebehlnd class
ln a complex nLler dlsLrlbuLed sysLem Lhe MvC archlLecLure place Lhe vlLal role of organlzlng Lhe
presenLaLlon Ller of Lhe sysLem
428 WhaL ls SCA?
A servlceorlenLed archlLecLure ls essenLlally a collecLlon of servlces 1hese servlces communlcaLe wlLh
each oLher 1he communlcaLlon can lnvolve elLher slmple daLa passlng or lL could lnvolve Lwo or more
servlces coordlnaLlng some acLlvlLy Some means of connecLlng servlces Lo each oLher ls needed
1he neL Lechnology lnLroduces Lhe SCA by mean of web servlces

1he SCA can be used as Lhe concepL Lo connecL mulLlple sysLems Lo provlde servlces lL has lLs greaL
share ln Lhe fuLure of Lhe l1 world
Accordlng Lo Lhe lmaglnary dlagram above we can see how Lhe Servlce CrlenLed ArchlLecLure ls belng
used Lo provlde a seL of cenLrallzed servlces Lo Lhe clLlzens of a counLry 1he clLlzens are glven a unlque
ldenLlfylng card where LhaL card carrles all personal lnformaLlon of each clLlzen Lach servlce cenLers
such as shopplng complex hosplLal sLaLlon and facLory are equlpped wlLh a compuLer sysLem where
LhaL sysLem ls connecLed Lo a cenLral server whlch ls responslble of provldlng servlce Lo a clLy As an
example when a cusLomer enLer Lhe shopplng complex Lhe reglonal compuLer sysLem reporL lL Lo Lhe
cenLral server and obLaln lnformaLlon abouL Lhe cusLomer before provldlng access Lo Lhe premlses 1he
sysLem welcomes Lhe cusLomer 1he cusLomer flnlshed Lhe shopplng and Lhen by Lhe Llme he leaves Lhe
shopplng complex he wlll be asked Lo go Lhrough a bllllng process where Lhe reglonal compuLer sysLem
wlll manage Lhe process 1he paymenL wlll be auLomaLlcally handled wlLh Lhe lnpuL deLalls obLaln from
Lhe cusLomer ldenLlfylng card
1he reglonal sysLem wlll reporL Lo Lhe clLy (compuLer sysLem of Lhe clLy) whlle Lhe clLy wlll reporL Lo Lhe
counLry (compuLer sysLem of Lhe counLry)
429 WhaL ls Lhe uaLa Access Layer?
1he daLa access layer (uAL) whlch ls a key parL of every nLler sysLem ls malnly conslsL of a slmple seL of
code LhaL does baslc lnLeracLlons wlLh Lhe daLabase or any oLher sLorage devlce 1hese funcLlonallLles
are ofLen referred Lo as C8uu (CreaLe 8eLrleve updaLe and ueleLe)
1he daLa access layer need Lo be generlc slmple qulck and efflclenL as much as posslble lL should noL
lnclude complex appllcaLlon/ buslness loglcs
l have seen sysLems wlLh lengLhy complex sLore procedures (S) whlch run Lhrough several cases
before dolng a slmple reLrleval 1hey conLaln noL only mosL parL of Lhe buslness loglc buL appllcaLlon
loglc and user lnLerface loglc as well lf S ls geLLlng longer and compllcaLed Lhen lL ls a good lndlcaLlon
LhaL you are burrlng your buslness loglc lnslde Lhe daLa access layer
430 WhaL ls Lhe 8uslness Loglc Layer?
l know for a facL LhaL Lhls ls a quesLlon for mosL buL from Lhe oLher hand by readlng many arLlcles l have
become aware LhaL noL everyone agrees Lo whaL buslness loglc acLually ls and ln many cases lLs [usL Lhe
brldge ln beLween Lhe presenLaLlon layer and Lhe daLa access layer wlLh havlng noLhlng much excepL
Laklng from one and passlng Lo Lhe oLher ln some oLher cases lL ls noL even been well LhoughL ouL Lhey
[usL Lake Lhe lefLovers from Lhe presenLaLlon layer and Lhe daLa access layer Lhen puL Lhem ln anoLher
layer whlch auLomaLlcally ls called Lhe buslness loglc layer Powever Lhere are no god sald Lhlngs LhaL
cannoL be changed ln sofLware world ?ou can change as and when you feel comforLable LhaL Lhe
meLhod you apply ls flexlble enough Lo supporL Lhe growLh of your sysLem 1here are many greaL ways
buL be careful when selecLlng Lhem Lhey can over compllcaLlng Lhe slmple sysLem lL ls a balance one
needs Lo flnd wlLh Lhelr experlence
As a general advlce when you deflne buslness enLlLles you musL declde how Lo map Lhe daLa ln your
Lables Lo correcLly deflned buslness enLlLles 1he buslness enLlLles should meanlngfully deflne
conslderlng varlous Lypes of requlremenLs and funcLlonlng of your sysLem lL ls recommended Lo ldenLlfy
Lhe buslness enLlLles Lo encapsulaLe Lhe funcLlonal/ ul (user lnLerface) requlremenLs of your appllcaLlon
raLher Lhan deflne a separaLe buslness enLlLy for each Lable of your daLabase lor example lf you wanL
Lo comblne daLa from couple of Lable Lo bulld a ul (user lnLerface) conLrol (Web ConLrol) lmplemenL
LhaL funcLlon ln Lhe 8uslness Loglc Layer wlLh a buslness ob[ecL LhaL uses couple of daLa ob[ecL Lo
supporL wlLh your complex buslness requlremenL
431 WhaL ls Cang of lour (Col) ueslgn aLLerns?
1he Cang of lour (Col) paLLerns are generally consldered Lhe foundaLlon for all oLher paLLerns 1hey are
caLegorlzed ln Lhree groups CreaLlonal SLrucLural and 8ehavloral Pere you wlll flnd lnformaLlon on
Lhese lmporLanL paLLerns
CreaLlonal aLLerns
AbsLracL lacLory CreaLes an lnsLance of several famllles of classes
8ullder SeparaLes ob[ecL consLrucLlon from lLs represenLaLlon
lacLory MeLhod CreaLes an lnsLance of several derlved classes
roLoLype A fully lnlLlallzed lnsLance Lo be copled or cloned
SlngleLon A class of whlch only a slngle lnsLance can exlsL
SLrucLural aLLerns
AdapLer MaLch lnLerfaces of dlfferenL classes
8rldge SeparaLes an ob[ecL's lnLerface from lLs lmplemenLaLlon
ComposlLe A Lree sLrucLure of slmple and composlLe ob[ecLs
uecoraLor Add responslblllLles Lo ob[ecLs dynamlcally
lacade A slngle class LhaL represenLs an enLlre subsysLem
llywelghL A flnegralned lnsLance used for efflclenL sharlng
roxy An ob[ecL represenLlng anoLher ob[ecL
8ehavloral aLLerns
Chaln of 8esp A way of passlng a requesL beLween a chaln of ob[ecLs
Command LncapsulaLe a command requesL as an ob[ecL
lnLerpreLer A way Lo lnclude language elemenLs ln a program
lLeraLor SequenLlally access Lhe elemenLs of a collecLlon
MedlaLor ueflnes slmpllfled communlcaLlon beLween classes
MemenLo CapLure and resLore an ob[ecLs lnLernal sLaLe
Cbserver A way of noLlfylng change Lo a number of classes
SLaLe AlLer an ob[ecLs behavlor when lLs sLaLe changes
SLraLegy LncapsulaLes an algorlLhm lnslde a class
1emplaLe MeLhod uefer Lhe exacL sLeps of an algorlLhm Lo a subclass
vlslLor ueflnes a new operaLlon Lo a class wlLhouL change
432 WhaL ls Lhe dlfference beLween AbsLracL lacLory and 8ullder deslgn paLLerns?
1he Lwo deslgn paLLerns are fundamenLally dlfferenL Powever when you learn Lhem for Lhe flrsL Llme
you wlll see a confuslng slmllarlLy So LhaL lL wlll make harder for you Lo undersLand Lhem 8uL lf you
conLlnue Lo sLudy evenLually you wlll geL afrald of deslgn paLLerns Loo lL ls llke lnfanL phobla once you
geL afrald aL your early age lL sLays wlLh you forever So Lhe resulL would be LhaL you never look back aL
deslgn paLLerns agaln LeL me see wheLher l can solve Lhls braln Leaser for you
ln Lhe lmage below you have boLh deslgn paLLern llsLed ln l am Lrylng Lo compare Lhe Lwo one on one
Lo ldenLlfy Lhe slmllarlLles lf you observe Lhe flgure carefully you wlll see an easlly undersLandable color
paLLern (same color ls used Lo mark Lhe classes LhaL are of slmllar klnd)

lease follow up wlLh Lhe numbers ln Lhe lmage when readlng Lhe llsLlng below
Mark #1 8oLh paLLerns have used a generlc class as Lhe enLryclass 1he only dlfference ls Lhe name of
Lhe class Cne paLLern has named lL as CllenL" whlle Lhe oLher named lL as ulrecLor"
Mark #2 Pere agaln Lhe dlfference ls Lhe class name lL ls AbsLracLlacLory" for one and 8ullder" for
Lhe oLher AddlLlonally boLh classes are of Lype absLracL
Mark #3 Cnce agaln boLh paLLerns have deflned Lwo generlc (WlndowslacLory ConcreLe8ullder)
classes 1hey boLh have creaLed by lnherlLlng Lhelr respecLlve absLracL class
Mark #4 llnally boLh seem Lo produce some klnd of a generlc ouLpuL
now where are we? Aren'L Lhey looklng almosL ldenLlcal? So Lhen why are we havlng Lwo dlfferenL
paLLerns here?
LeL's compare Lhe Lwo agaln slde by slde for one lasL Llme buL Lhls Llme focuslng on Lhe dlfferences
AbsLracL lacLory Lmphaslzes a famlly of producL ob[ecLs (elLher slmple or complex)
8ullder locuses on consLrucLlng a complex ob[ecL sLep by sLep
AbsLracL lacLory locus on *whaL* ls made
8ullder locus on *how* lL ls made
AbsLracL lacLory locus on deflnlng many dlfferenL Lypes of *facLorles* Lo bulld many *producLs* and lL
ls noL a one bullder for [usL one producL
8ullder locus on bulldlng a one complex buL one slngle *producL*
AbsLracL lacLory uefers Lhe cholce of whaL concreLe Lype of ob[ecL Lo make unLll run Llme
8ullder Plde Lhe loglc/ operaLlon of how Lo complle LhaL complex ob[ecL
AbsLracL lacLory *Lvery* meLhod call creaLes and reLurns dlfferenL ob[ecLs
8ullder Cnly Lhe *lasL* meLhod call reLurns Lhe ob[ecL whlle oLher calls parLlally bulld Lhe ob[ecL
SomeLlmes creaLlonal paLLerns are complemenLary So you can [oln one or many paLLerns when you
deslgn your sysLem As an example bullder can use one of Lhe oLher paLLerns Lo lmplemenL whlch
componenLs geL bullL or ln anoLher case AbsLracL lacLory 8ullder and roLoLype can use SlngleLon ln
Lhelr lmplemenLaLlons So Lhe concluslon would be LhaL Lhe Lwo deslgn paLLerns exlsL Lo resolve Lwo
Lype of buslness problems so even Lhough Lhey look slmllar Lhey are noL
l hope LhaL Lhls shed some llghL Lo resolve Lhe puzzle lf you sLlll don'L undersLand lL Lhen Lhls Llme lL ls
noL you lL has Lo be me and lL ls slnce LhaL l don'L know how Lo explaln lL
3 WhaL ls Lhe Concluslon?
l donL Lhlnk LhaL lL ls reallsLlc Lrylng Lo make a programmlng language be everyLhlng Lo everybody 1he
language becomes bloaLed hard Lo learn and hard Lo read lf everyLhlng plus Lhe klLchen slnk ls Lhrown
ln ln anoLher word every language has Lhelr llmlLaLlons As sysLem archlLecL and deslgner we should be
able Lo fully and more lmporLanLly correcLly (Lhls also mean LhaL you shouldn'L use a balllsLlc mlsslle Lo
klll a fly or hlre l8l Lo caLch Lhe fly) uLlllze Lhe avallable Lools and feaLures Lo bulld usable susLalnable
malnLalnable and also very lmporLanLly expandable sofLware sysLems LhaL fully uLlllze Lhe feaLure of Lhe
language Lo brlng a compeLlLlvely advance sysLem Lo Lhelr cusLomers ln order Lo do lL Lhe foundaLlon of
a sysLem places a vlLal role 1he deslgn or Lhe archlLecLure of a sofLware sysLem ls Lhe foundaLlon lL hold
Lhe sysLem LogeLher hence deslgnlng a sysLem properly (Lhls never mean an *over* deslnglng) ls Lhe key
Lo Lhe success When you Lalk abouL deslgnlng a sofLware sysLem Lhe correcL handllng of CC concepL
ls very lmporLanL l have made Lhe above arLlcle rlcher wlLh ldea buL sLlll kepL lL shorL so LhaL one can
learn/ remlnd all of lmporLanL concepL aL a glance Pope you all wlll en[oy readlng lL
llnally afLer readlng all Lhese one may argue wlLh me saylng LhaL anybody can wrlLe all Lhese concepL
deflnlLlons buL do l know how/ when Lo apply Lhem ln real world sysLems So for Lhem Lo see Lhese
concepLs belng applled ln real world sysLems please check Lhe source code of Lhe laLesL of my open
source pro[ecL name 8ockeL lramework
noLe lor newbles 8ockeL lramework ls golng Lo be llLLle Loo advance buL check lL use lL and revlew lL lf
you have any quesLlons/ crlLlclsms around my deslgn donL heslLaLe Lo shooL Lhem here or Lhere
6 WhaL l 8eferred?
MSun Llbrary hLLp//msdn2mlcrosofLcom/enus/llbrary/defaulLaspx
racLlcal Approach Lo CompuLer SysLems ueslgn and ArchlLecLure
hLLp//wwwcodepro[ecLcom/userlLems/SysLem_ueslgnasp
lnLroducLlon WhaL ls Cb[ecLCrlenLed rogrammlng?
hLLp//wwwlnfufscbr/poo/smallLalk/lbm/LuLorlal/oophLml
8aslc Cb[ecLCrlenLed ConcepLs hLLp//wwwLoacom/pub/oobaslcs/oobaslcshLm
lnherlLance and olymorphlsmSpeclallzaLlon and CenerallzaLlon hLLp//encsharp
onllneneL/lnherlLance_and_olymorphlsmL28094SpeclallzaLlon_and_CenerallzaLlon
AbsLracLlon and CenerallzaLlon hLLp//cswwcedu/aabyan/L8ook/P1ML/AbsCenhLml
Cb[ecL CrlenLed Analysls and ueslgn 1eam
hLLp//aLlaskennesawedu/dbraun/csls4630/Au/lndexhLm
CllenL/Server SofLware ArchlLecLuresAn Cvervlew
hLLp//wwwselcmuedu/sLr/descrlpLlons/cllenLserverhLml
ServlceorlenLed archlLecLure (SCA) deflnlLlon hLLp//wwwservlcearchlLecLurecom/web
servlces/arLlcles/servlceorlenLed_archlLecLure_soa_deflnlLlonhLml
hLLp//wwwdofacLorycom/aLLerns/aLLernsaspx
hLLp//wwwob[ecLmenLorcom