Anda di halaman 1dari 6

CCS V|deos know|edge Capture

Dot Net Arch|tecture CCS A V|deo Ser|es



Jhat |s the rob|em w|th funct|ona| programm|ng?
lour baslc problems wlLh Lhe funcLlonal programmlng are
eusablllLy
LenslblllLy
lmpllclLy
,alnLalnablllLy

eusab|||ty ulfferenL coples of same code ln dlfferenL ul (user lnLerface) lncreases Lhe redundancy ln Lhe code
Lxtens|b|||ty 1here ls no opLlon of lnherlLlng Lhe funcLlonallLy We have Lo creaLe Lhe new funcLlon Lo make Lhe few
ad[usLmenLs only
S|mp||c|ty 8ecause of Lhe above Lwo reasons we end up wlLh Lhe very compllcaLed code whlch become very dlfflculL Lo
malnLaln
Ma|nta|nab|||ty as our code does noL provlde reusablllLy eLenslblllLy and slmpllclLy would lead Lo malnLaln Lhe code aL
laLer sLages ln any changes are requlred

2 Can you def|ne the CC and the 4 pr|nc|p|es of CC?
b[ecL orlenLed programmlng ls Lhe deslgn approach where we Lhlnk ln Lhe Lerms of ob[ecLs
lL's a deslgn phllosophy where we can vlsuallze ln Lerms of self susLalned b[ecLs

lour dlfferenL lssues wlLh Lhe funcLlonal programmlng are resolved by uslng Lhe below Lermlnologles
eusab|||ty lasses b[ecLs
Lxtens|b|||ty lnherlLance AggregaLlon and omposlLlon
S|mp||c|ty AbsLracLlon ncapsulaLlon olymorphlsm
Ma|nta|nab|||ty Lhe enLlre above comblne Lo make Lhe code malnLalnable

Abstract|on allow comple words Lo represenL ln a slmpllfled manner by eposlng only Lhe necessary properLles lor
lnsLance lnsLead of deflnlng Lhe Lhousands of colors olor can be absLracLed by 8
Lncapsu|at|on process of hldlng Lhe lnner deLalls from Lhe eLernal world wlLh LhaL maklng Lhe ob[ecL lnLerface slmple
Inher|tance Lhey are used Lo deflclL Lhe parenL chlld relaLlonshlp o we can have a class wlLh [usL seL and geL We can
Lhen lnherlL and creaLe a new speclallzed class whlch does daLabase operaLlons
o|ymorph|sm we wanL an ob[ecL Lo play dlfferenL role dependlng on dlfferenL slLuaLlons lor lnsLance we can class
whlch does daLabase ob[ecLs on ; erver and racle uependlng on Lhe connecLlon sLrlng lL wlll morph lLs role Lo do
; operaLlons or racle peraLlons oly means many and ,orph means change

3 Jhat are c|ass and ob[ects?
C|ass A class ls slmply a Lype of ob[ecL lL ls a blueprlnL/plan/LemplaLe LhaL descrlbes Lhe deLalls of Lhe ob[ecL A class ls a
blueprlnL from whlch Lhe lndlvldual ob[ecLs are creaLed A class ls composed of Lhree Lhlngs a name aLLrlbuLes and
operaLlons
Cb[ects lL's an lnsLance of a class lass ls broughL llve by creaLlng ob[ecLs An ob[ecL can be consldered a Lhlng LhaL can
perform acLlvlLles 1he seL of acLlvlLles whlch ob[ecL performs deflnes Lhe ob[ecLs behavlor

4 Jhat |s |nher|tance?
lnherlLance addresses Lhe problem of eLenslblllLy 8y uslng Lhe lnherlLance we can creaLe a fresh chlld class whlch has
all Lhe quallLles of parenL plus eLra new quallLles of hlmself also
publlc class clsroducL

publlc lnL geL1oLalosL(lnL lnL;Ly lnL lnLerroducL)

reLurn lnL;Ly * lnLerroducL


publlc class clsroducLWlLhulscounL c|sroduct

publlc lnL geL1oLalosL(lnL lnL;Ly lnL lnLerroducL lnL lnLulscounL)

reLurn (geL1oLalosL(lnL;Ly lnLerroducL) lnLulscounL)



S Jhat |s po|ymorph|sm over|oad|ng overr|d|ng and v|rtua| funct|ons?
8y uslng Lhe polymorphlsm you can have more slmpllfled lnLerfaces and neL code
oly means many ,orphlsm means forms lL's an ablllLy of ob[ecLs or meLhod Lo Lake dlfferenL forms as per
slLuaLlons
@ypes of po|ymorph|sm

Stat|c po|ymorph|sm Method Cver|oad|ng

publlc class clsroducL

publlc lnL geL1oLalosL(lnL lnL;Ly lnL lnLerroducL)

reLurn lnL;Ly * lnLerroducL

publlc lnL geL1oLalosL(lnL lnL;Ly lnL lnLerroducL lnL lnLulscounL)

reLurn (geL1oLalosL(lnL;Ly lnLerroducL) lnLulscounL)


consume c/oss in ul
clsroducL ob[roducL new clsroducL()
lf (lnLulscounL 0)

LL1oLalosL1eL ob[roducLgeL1oLalosL(lnL;LylnLerroducLosL)1oLrlng()

else

LL1oLalosL1eL ob[roducLgeL1oLalosL(lnL;Ly lnLerroducLosLlnLulscounL)1oLrlng()


Dynam|c po|ymorph|sm Method Cverr|d|ng
publlc class clsroducL

publlc v|rtua| sLrlng geL1oLalosL(lnL lnL;Ly lnL lnLerroducL sLrlng sLrurrency)

reLurn 1he LoLal cosL ls + geL1oLalosL(lnL;Ly lnLerroducL)1oLrlng() + + sLrurrency


publlc class clsroducLWlLhulscounL c|sroduct

publlc overr|de sLrlng geL1oLalosL(lnL lnL;Ly lnL lnLerroducL sLrlng sLrurrency)

reLurn 1he LoLal cosL wlLh dlscounL of 10
+ geL1oLalosL(lnL;Ly lnLerroducL10)1oLrlng() +
+ sLrurrency


consume c/oss in ul
clsroducL ob[roducL

lf (lnLulscounL 0)

ob[roducL new clsroducL()
,essage8ohow(ob[roducLgeL1oLalosL(lnL;Ly lnLerroducLosLln)1oLrlng())

else

ob[roducL new clsroducLWlLhulscounL()
,essage8ohow(ob[roducLgeL1oLalosL(lnL;Ly lnLerroducLosL ln)1oLrlng())


Lxp|a|n encapsu|at|on abstract|on?
nAuA1ln ls noLhlng buL u hlde complelLy lL helps us Lo make our class slmpler Lo use

ncapsulaLlon means hldlng complelLy

Jithout encopsu/otion
clsroducL ob[ new clsroducL()
ob[ls;LyreaLer(lnL;Ly)
ob[lsroducLosLZero(lnLosL)
ob[roducLosL lnLroducLosL
ob[;Ly lnL;Ly

Jith encopsu/otion
clsroducL ob[ new clsroducL()
ob[roducLosL lnLroducLosL
ob[;Ly lnL;Ly

ncapsulaLlon can be lmplemenLed by access modlflers

r|vate only members of class have access
ub||c all members have access ln all classes and pro[ecLs
rotected all member ln currenL class and derlved classes can access Lhe varlables
re|nd (Interna| |n C#) only members ln currenL pro[ecL have access Lo Lhe elemenLs
rotected re|nd (protected |nterna| |n C#) all members ln currenL pro[ecL and all members ln derlved class can
access Lhe varlables

A81A1ln only shows whaL ls necessary
AbsLracLlon and encapsulaLlon boLh complemenL each oLher
AbsLracLlon ls achleved Lhrough encapsulaLlon
AbsLracLlon solves Lhe problem ln Lhe deslgn slde whlle encapsulaLlon ls lmplemenLaLlon

Jhat |s an abstract c|ass?
AbsLracL classes represenL base classes and we cannoL creaLe ob[ecLs of Lhese classes ?ou can make use of absLracL
classes Lo lmplemenL such funcLlonallLy ln uslng Lhe modlfler absLracL An absLracL class means LhaL no ob[ecLs of Lhls
class can be lnsLanLlaLed buL can made derlvaLlons of Lhls An absLracL class can conLaln elLher Lhe absLracL meLhod or
non absLracL meLhod AbsLracL classes cannoL be deflne as sLaLlc sealed prlvaLe proLecLed lnLernal absLracL class ls
defaulL ubllc
AbsLracL members do noL have any lmplemenLaLlon ln Lhe absLracL class buL Lhe same has Lo be provlded ln lLs derlved
class AbsLracL meLhods need Lo be deflned ln derlved class absLracL meLhod cannoL be marked as vlrLual
1he access modlflers of Lhe absLracL meLhods should be same ln boLh Lhe absLracL and derlved class

absLracL class u8

publlc absLracL vold onnecL()
publlc sLrlng u8lpAddress()

reLurn 101011



class ;erver u8


publlc overrlde vold onnecL()

onsoleWrlLelne(1hls meLhod wlll connecL Lo ; erver)


class racle u8


publlc overrlde vold onnecL()

onsoleWrlLelne(1hls meLhod wlll connecL Lo racle)



Def|ne Interface
An lnLerface looks llke a class buL has no lmplemenLaLlon lL only conLalns deflnlLlons of evenLs lndeers meLhods
and/or properLles 1he reason lnLerface only provldes deflnlLlons are because Lhey are lnherlLed by class and sLrucLs
whlch musL provlde lmplemenLaLlon for each lnLerface member deflned

lnLerfaces are used for
nforce sLandardlzlng of vocabulary
1hey help decupllng

Lnforce standard|z|ng of vocabu|ary
lnLerface luaLabase

vold updaLe()

class clsusLomer luaLabase

publlc vold updaLe()




class clsuppller luaLabase

publlc vold updaLe()





Decup||ng
lnLerface lub

vold updaLe()

publlc class cls;erver lub

publlc vold updaLe()



publlc class clsracle lub

publlc vold updaLe()



publlc class clsusLomerb[ecL

publlc vold updaLe(lub ob[)

ob[updaLe()



lnLerface keyword ls used Lo deflne lnLerfaces
lnLerfaces cannoL have fleld varlables
lnLerfaces cannoL have lmplemenLed funcLlons and meLhods
All meLhods need Lo be lmplemenLed ln Lhe derlved class
lnLerface can used Lo lmplemenL run Llme polymorphlsm
?ou can lmplemenL mulLlple lnLerfaces on Lhe slngle class
All lnLerface meLhods are publlc

Jhat |s the d|ff between abstract |nterface?
An absLracL class can have absLracL meLhods as well as non absLracL meLhods 8uL ln Lhe lnLerface all Lhe
members are lmpllclLly absLracL and all Lhe members of Lhe lnLerface musL Lo lLs derlved class
1he members of lnLerface are publlc wlLh no lmplemenLaLlon AbsLracLs meLhods can have proLecLed parLs
sLaLlc meLhods eLc
AbsLracL classes can add more funcLlonallLy wlLhouL desLroylng Lhe chlld classes ln lnLerface creaLlon of
addlLlonal funcLlons wlll have an effecL on lLs chlld classes due Lo Lhe necessary lmplemenLaLlon of lnLerface
meLhods Lo classes

Jhat |s shadow|ng?
hadowlng ls Lhe concepL whlch ls used Lo change Lhe elemenL of Lhe parenL class lease use Lhe below code for more
eplanaLlon

publlc class sales

publlc lnL lnvolcenumber seL geL

publlc class salesverslon2 sales

publlc ob[ecL lnvolcenumber seL geL


class program

sLaLlc vold maln(sLrlng args)

sales b[1 new sales()
b[1lnvolcenumber 123

salesverslon2 b[2 new salesverslon2()
b[2lnvolcenumber 12346



n1 shadowlng replaces currenL elemenL of Lhe parenL verrldlng only changes Lhe lmplemenLaLlon

Can we |mp|ement |nterfaces w|th same method names |n C#?
?es we can lmplemenL lnLerface wlLh same meLhod name by quallfylng Lhe meLhod name by Lhe lnLerface name

lnLerface l1

vold meLhod1()

lnLerface l2

vold meLhod1()


class A l1 l2

publlc vold l1meLhod1

sLrlng sLr 1hls ls called by l1

publlc vold l1meLhod1

sLrlng sLr 1hls ls called by l2



sLaLlc vold ,aln(sLrlng args)

l1 l1b[ new A()
l1b[meLhod1()

l2l2b[ new A()
l2b[meLhod1()

Anda mungkin juga menyukai