You are on page 1of 12

lnLerface

W lL ls a speclal Lype of class


W lnLerfaces descrlbe a group of relaLed
funcLlonallLles LhaL can belong Lo any class or
sLrucL
W lnLerfaces conslsL of meLhods properLles
evenLs lndexers or any comblnaLlon of Lhose
four member Lypes An lnLerface cannoL
conLaln consLanLs flelds operaLors lnsLance
consLrucLors desLrucLors or Lypes lL cannoL
conLaln sLaLlc members lnLerfaces members
are auLomaLlcally publlc and Lhey cannoL
lnclude any access modlflers
Jhy and when Lo use lnLerface?
W LxLernal parLy can undersLand Lhe
funcLlonallLy of Lhe program easlly
W lor Lhe proper execuLlon of program
W Jhen a class or sLrucL lmplemenLs an
lnLerface Lhe class or sLrucL provldes an
lmplemenLaLlon for all of Lhe members
deflned by Lhe lnLerface
W lf lL ls requlred Lo lmplemenL Lhe same
funcLlon by all Lhe classes Lhen lnLerface musL
be declared aL Lhe beglnnlng
W lf Lhe funcLlon ls declared ln Lhe lnLerface Lhen
all Lhe classes musL lmplemenL LhaL same
funcLlon
W lf we change any funcLlon ln Lhe lnLerface Lhen
we auLomaLlcally geL Lhe errors for Lhe classes
belonglng Lo lL
W JlLh Lhe help of Lhls lL ls very easy Lo locaLe all
Lhe classes whlch are requlred Lo modlfy
W MalnLenance becomes easy
lnherlLance
W ln ob[ecLorlenLed programmlng lnherlLance
ls Lhe concepL LhaL when a class of ob[ecLs ls
deflned any subclass LhaL ls deflned can
lnherlL Lhe deflnlLlons of one or more general
classes
@ypes
A
8
A
8
C
Slngle lnherlLance
MulLlple lnherlLance
A
8
C
MulLllevel lnherlLance
A
8 C u
Plerarchlcal lnherlLance
Jhy ?
W lL ls always nlce lf we could reuse someLhlng
LhaL already exlsLs raLher Lhan Lrylng Lo creaLe
Lhe same allover agaln
W lL would noL only save Llme and money buL
also reduce frusLraLlon and lncrease rellablllLy
W lL can save Lhe efforLs of developlng and
LesLlng Lhe same agaln
Jhen?
@here are several oLher reasons why you mlghL wanL Lo use
lnLerfaces lnsLead of class lnherlLance
W lnLerfaces are beLLer sulLed Lo slLuaLlons ln whlch your appllcaLlons
requlre many posslbly unrelaLed ob[ecL Lypes Lo provlde cerLaln
funcLlonallLy
W lnLerfaces are more flexlble Lhan base classes because you can
deflne a slngle lmplemenLaLlon LhaL can lmplemenL mulLlple
lnLerfaces
W lnLerfaces are beLLer ln slLuaLlons ln whlch you do noL need Lo
lnherlL lmplemenLaLlon from a base class
W lnLerfaces are useful ln cases where you cannoL use class
lnherlLance lor example sLrucLures cannoL lnherlL from classes
buL Lhey can lmplemenL lnLerfaces
courLesy
W wwwMsdncom
W wwwCooglecom
W wwwJlklpedlacom
W Cop wlLh c++ by 8alagurusamy
@hank you

You might also like