• No results found

03 ABAP Objects -Inheritance

N/A
N/A
Protected

Academic year: 2021

Share "03 ABAP Objects -Inheritance"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)

 © IBM Corporation 2013

 © IBM Corporation 2013

ABAP Objects Advanced -Inheritance

(2)

ABAP Objects Advanced : Inheritance Topics

ABAP Objects Advanced : Inheritance Topics

 ConceptConcept

 Snta! and "isibilitSnta! and "isibilit

 Abstract Classes and Met#ods Abstract Classes and Met#ods

 $inal Classes and Met#ods$inal Classes and Met#ods

 Static Co%ponents in In#eritanceStatic Co%ponents in In#eritance

 Met#od &ede'initionMet#od &ede'inition

 Constructor in In#eritanceConstructor in In#eritance

 Object &e'erences in In#eritanceObject &e'erences in In#eritance

(3)

Inheritance : Concept

Inheritance : Concept

 In#eritance is one o' tIn#eritance is one o' t#e %ost po)er'ul 'eature o' object #e %ost po)er'ul 'eature o' object oriented pro(ra%%in(*oriented pro(ra%%in(*

 In#eritance is t#e process o' creatin( ne) classes+ called derived classes or SubIn#eritance is t#e process o' creatin( ne) classes+ called derived classes or Sub Classes or c#ild classes 'ro% e!istin( classes c

Classes or c#ild classes 'ro% e!istin( classes called base classes or Superalled base classes or Super Classes or parent classes*

Classes or parent classes*

 ,#e derived class in#erits all t#e capabilities o' t#e base class but ,#e derived class in#erits all t#e capabilities o' t#e base class but can addcan add e%bellis#%ents and re'ine%ents o' its

e%bellis#%ents and re'ine%ents o' its o)n* ,#e base class is unc#an(ed b to)n* ,#e base class is unc#an(ed b t#is#is process*

process*

Grand Parent Class Grand Parent Class

Parent Class Parent Class

C#ild Class C#ild Class

Sin(le In#eritance supported Sin(le In#eritance supported

b ABAP Objects b ABAP Objects

Parent Class

Parent Class Parent ClassParent Class

C#ild Class C#ild Class

Multiple In#eritance not

Multiple In#eritance not

supported b ABAP

supported b ABAP

Objects

(4)

Inheritance : Concept !Contd"#

Inheritance : Concept !Contd"#

 ,#e relations#ip bet)een t#e,#e relations#ip bet)een t#e base classes and t#e derived base classes and t#e derived classes can be

classes can be represented in anrepresented in an In#eritance tree* #ere base

In#eritance tree* #ere base

classes o' eac# derived class can classes o' eac# derived class can be retraced alon( an uni.ue pat# be retraced alon( an uni.ue pat# to a sin(le root node o' t#e tree* to a sin(le root node o' t#e tree*

 A Sup A Super Class is a Generali/ationer Class is a Generali/ation o' its Sub Classes

o' its Sub Classes and on t#eand on t#e ot#er #and a Sub Class is a ot#er #and a Sub Class is a

Speciali/ation o' its Super Class* Speciali/ation o' its Super Class*

$%per C&ass $%per C&ass P%b&ic: P%b&ic:   Protected:   Protected:  Private:  Private: C&ass C1 C&ass C1 P%b&ic: P%b&ic:   Protected:   Protected:  Private:  Private: C&ass C2 C&ass C2 P%b&ic: P%b&ic:   Protected:   Protected:  Private:  Private: C&ass C3 C&ass C3 &oot node &oot node Generali/ed Generali/ed Class Class Speciali/ed Speciali/ed Class Class

More speciali/ed class More speciali/ed class       '       '    e    e     n     n     e     e     r     r     a     a       &       &       i       i    (    (    a    a       t       t       i       i    o    o    n    n

      $       $    p    p     e     e     c     c       i       i    a    a       &       &       i       i    (    (    a    a       t       t       i

(5)

Inheritance:

Inheritance:

Adva

Adva

ntaes

ntaes

 In#eritance per%its codeIn#eritance per%its code +e%sabi&it.+e%sabi&it.* &eusin( e!istin( code re%oves code* &eusin( e!istin( code re%oves code redundanc and saves ti%e  %one*

redundanc and saves ti%e  %one*

 Co%%on co%ponents e!ist onl in Co%%on co%ponents e!ist onl in t#e Super Class and t#e Super Class and %aintained%aintained Centra&&.Centra&&.**

 Once a base class is )ritten and tested+ it Once a base class is )ritten and tested+ it need not be touc#ed a(ain* ,#isneed not be touc#ed a(ain* ,#is increases pro(ra%

(6)

Inheritance : $.nta and isibi&it.

Inheritance : $.nta and isibi&it.

CA$$ s%perc&ass 456I7ITIO7"

CA$$ s%perc&ass 456I7ITIO7"

P8BIC $5CTIO7" P8BIC $5CTIO7" P%b&ic co9ponents P%b&ic co9ponents P+OT5CT54 $5CTIO7" P+OT5CT54 $5CTIO7" Protected co9ponents Protected co9ponents P+IAT5 $5CTIO7" P+IAT5 $5CTIO7" Private co9ponents Private co9ponents 574CA$$" 574CA$$"

CA$$ s%bc&ass 456I7ITIO7 I75+ITI7' 6+OM

CA$$ s%bc&ass 456I7ITIO7 I75+ITI7' 6+OM

s%perc&ass" s%perc&ass" P8BIC $5CTIO7" P8BIC $5CTIO7" P%b&ic co9ponents P%b&ic co9ponents P%b&ic co9ponents P%b&ic co9ponents !s%perc&ass# !s%perc&ass# P+OT5CT54 $5CTIO7" P+OT5CT54 $5CTIO7" Protected co9ponents Protected co9ponents Protected co9ponents Protected co9ponents !s%perc&ass# !s%perc&ass# P+IAT5 $5CTIO7" P+IAT5 $5CTIO7" Private section Private section 

 ,#e public and protected,#e public and protected

co%ponents o' t#e Super Class are co%ponents o' t#e Super Class are visible in t#e Sub Class*

visible in t#e Sub Class*

 Private section o' t#e Super Class isPrivate section o' t#e Super Class is not visible in t#e Sub Classes*

not visible in t#e Sub Classes*

 Private co%ponents o' t#e SubPrivate co%ponents o' t#e Sub Class can #ave sa%e na%e as t#e Class can #ave sa%e na%e as t#e private co%ponent o' t#e Super private co%ponent o' t#e Super Class*

Class*

 Public and Protected co%ponents o'Public and Protected co%ponents o' t#e Sub Class can not #ave t#e

t#e Sub Class can not #ave t#e

sa%e na%e as t#at #ave been used sa%e na%e as t#at #ave been used in Super Class*

(7)

Inheritance : Abstract c&asses and 9ethods

Inheritance : Abstract c&asses and 9ethods

CA$$ c&s%per 456I7ITIO7"

CA$$ c&s%per 456I7ITIO7"

P8BIC

P8BIC $5CTIO7"$5CTIO7"

M5TO4$:

M5TO4$: de9o1 de9o1 AB$T+AAB$T+ACT<CT<

  de9o2"

  de9o2"

574CA$$"

574CA$$"

CA$$ c&s%b 456I7ITIO7

CA$$ c&s%b 456I7ITIO7

I75+ITI7' 6+OM c&s%per"

I75+ITI7' 6+OM c&s%per"

P8BIC

P8BIC $5CTIO7"$5CTIO7"

M5TO4$

M5TO4$ de9o1 de9o1 +5456I7ITIO7"+5456I7ITIO7"

574CA$$"

574CA$$"

 A class de'in A class de'ined ased as AB$T+ACTAB$T+ACT cannot be cannot be instantiated + t#at is one cannot use

instantiated + t#at is one cannot use C+5AT5C+5AT5 OB=5CT

OB=5CT )it# re'erence to t#e class* )it# re'erence to t#e class*

 Abstract class can onl be accessed usin( its Abstract class can onl be accessed usin( its Static Co%ponents or its Sub Classes*

Static Co%ponents or its Sub Classes*

 Abstract class serves as a te%plate 'or Sub Abstract class serves as a te%plate 'or Sub Classes

Classes

 I' a class I' a class contains an abstract %et#od t#econtains an abstract %et#od t#e )#ole class beco%es abstract*

)#ole class beco%es abstract*

 A %et#o A %et#od+ )#ic# is abstract+ s#ould bed+ )#ic# is abstract+ s#ould be rede'ined in derived class*

rede'ined in derived class*

 An Ab An Abstract class can declare and i%ple%entstract class can declare and i%ple%ent non abstract %et#ods )#ic# its Sub Classes non abstract %et#ods )#ic# its Sub Classes can use )it# or )it#out rede'inin( t#e%*

can use )it# or )it#out rede'inin( t#e%*

+ede>inin the Abstract 9ethod o> +ede>inin the Abstract 9ethod o> $%per C&ass in the $%b C&ass

$%per C&ass in the $%b C&ass Abstract 9ethod

(8)

Inheritance : 6ina& c&asses and 9ethods

Inheritance : 6ina& c&asses and 9ethods

 A A >ina&>ina& class can not be class can not be inheritedinherited 'urt#er*

'urt#er*

 All Met#ods o' a All Met#ods o' a >ina&>ina& class areclass are in#erentl 'inal and %ust not be in#erentl 'inal and %ust not be declared as

declared as >ina&>ina& in t#e class in t#e class de'inition*

de'inition*

 A A >ina&>ina& %et#od can not be%et#od can not be rede>inedrede>ined 'urt#er*

'urt#er*

 I' a %et#od o' a non-'inal class is I' a %et#od o' a non-'inal class is 'inal'inal t#en t#at class can be in#erited but t#en t#at class can be in#erited but t#at %et#od cannot be rede'ined* t#at %et#od cannot be rede'ined*

CA$$

CA$$ >ina&c&ass 456>ina&c&ass 456I7ITIO7 I7ITIO7 6I7A"6I7A"

" " " " " " " "

" " " " " " " "

574CA$$"

574CA$$"

CA$$

CA$$ derivedc&ass derivedc&ass 456I7ITIO7456I7ITIO7

I75+ITI7' 6+OM >ina&c&ass "

I75+ITI7' 6+OM >ina&c&ass "

"

" "" "" " " " " " " " " " " " " ""

574CA$$"

574CA$$"

CA$$ s%perc&ass 456I7ITIO7 "

CA$$ s%perc&ass 456I7ITIO7 "

" " " " " " " "

" " " " " " " "

M5TO4$

M5TO4$ >ina&9ethod >ina&9ethod 6I7A"6I7A"

574CA$$"

574CA$$"

CA$$

CA$$ s%bc&ass s%bc&ass 456I7ITIO7 456I7ITIO7 I75+ITI7'I75+ITI7'

6+OM s%perc&ass "

6+OM s%perc&ass "

"

" "" "" " " " " " " " " " " " " ""

M5TO4$

M5TO4$ >ina&9ethod >ina&9ethod rede>inition"rede>inition"

574CA$$"

(9)

Inheritance : $tatic co9ponents

Inheritance : $tatic co9ponents

 ,#e,#e p%b&icp%b&ic and and protectedprotected static static

co%ponents 1%et#ods  attributes3 o' co%ponents 1%et#ods  attributes3 o' t#e Super Class are visible in t#e Sub t#e Super Class are visible in t#e Sub Class*

Class*

 Public static co%ponents can bePublic static co%ponents can be accessed t#rou(# t#e class

accessed t#rou(# t#e class

co%ponent selector used )it# an co%ponent selector used )it# an class in t#e respective pat# o'

class in t#e respective pat# o' in#eritance tree*

in#eritance tree*

CA$$ basec&ass 456I7ITIO7"

CA$$ basec&ass 456I7ITIO7"

P8BIC $5CTIO7"

P8BIC $5CTIO7"

CA$$-4

CA$$-4AATTA A : : na9e na9e TP5 $T+I7'TP5 $T+I7'

A

A85 85 ABAP"ABAP"

  DDD""

  DDD""

574CA$$"

574CA$$"

CA$$

CA$$ derivedc&ass derivedc&ass 456I7ITIO7456I7ITIO7

I75+ITI7' 6+OM basec&ass"

I75+ITI7' 6+OM basec&ass"

" " "" "" " " " " " " " " " " " " "" 574CA$$" 574CA$$" $TA+T-O6-$55CTIO7" $TA+T-O6-$55CTIO7" basec&assEFna9e" basec&assEFna9e" derivedc&assEFna9e" derivedc&assEFna9e" $tatic co9ponent $tatic co9ponent

$tatic co9ponent is accessed $tatic co9ponent is accessed thro%h c&ass co9ponent

thro%h c&ass co9ponent

se&ector >ro9 the derived c&ass se&ector >ro9 the derived c&ass as Ge&& as >ro9 the base c&ass as Ge&& as >ro9 the base c&ass

(10)

Inheritance : Method +ede>inition

Inheritance : Method +ede>inition

 +ede>inition+ede>inition is )#en t#e is )#en t#e

i%ple%entation o' an in#erited i%ple%entation o' an in#erited instance

instance %et#od is c#an(ed 'or t#e %et#od is c#an(ed 'or t#e Sub Class )it#out c#an(in( its

Sub Class )it#out c#an(in( its si(nature*

si(nature*

 $tatic 9ethods cant be rede>ined$tatic 9ethods cant be rede>ined**

 ,#e para%eters re%ain sa%e in t#e,#e para%eters re%ain sa%e in t#e derived class as it )as in base class* derived class as it )as in base class*

 In t#e rede'ined %et#od use tIn t#e rede'ined %et#od use t#e#e $8P5+

$8P5+ pseudo re'erence to access pseudo re'erence to access t#e ori(inal %et#od o' t#e base class* t#e ori(inal %et#od o' t#e base class*

CA$$ basec&ass 456I7ITIO7"

CA$$ basec&ass 456I7ITIO7"

P8BIC $5CTIO7"

P8BIC $5CTIO7"

M5TO4$:

M5TO4$: 9eth"9eth"

" " " " " " " "

" " " " " " " "

574CA$$"

574CA$$"

CA$$

CA$$ derivedc&ass derivedc&ass 456I7ITIO7 456I7ITIO7 I75+ITI7'I75+ITI7'

6+OM basec&ass "

6+OM basec&ass "

P8BIC

P8BIC $5CTIO7"$5CTIO7"

M5TO4$:

M5TO4$: 9eth 9eth +5456I7ITIO7"+5456I7ITIO7"

"

" "" "" " " " " " " " " " " " " ""

574CA$$"

574CA$$"

CA$$ derivedc&ass IMP5M57TATIO7 "

CA$$ derivedc&ass IMP5M57TATIO7 "

M5TO4$ 9eth"

M5TO4$ 9eth"

CA$$

CA$$ M5TO4 M5TO4 $8P5+-F9eth"$8P5+-F9eth"

DDD DDD  574M5TO4"  574M5TO4" 574CA$$" 574CA$$"

+ede>inin the base c&ass 9ethod in the +ede>inin the base c&ass 9ethod in the

derived c&ass derived c&ass

Ca&&in the $%per C&ass 9ethod %sin Ca&&in the $%per C&ass 9ethod %sin

$8P5+ He.Gord $8P5+ He.Gord

(11)

Inheritance : Instance Constr%ctors

Inheritance : Instance Constr%ctors

  As all public and protected As all public and protected

co%ponents+ Sub Class in#erits t#e co%ponents+ Sub Class in#erits t#e constructor %et#od i' it is present in constructor %et#od i' it is present in t#e in#eritance tree*

t#e in#eritance tree*

 I' an object o' Sub Class I' an object o' Sub Class is createdis created at t#is ti%e t#e in#erited instance at t#is ti%e t#e in#erited instance attributes and private attributes o' attributes and private attributes o' t#e Super Classes %ust also be t#e Super Classes %ust also be initiali/ed*

initiali/ed*

  As t#e private attributes o' t#e As t#e private attributes o' t#e Super Class is not visible to Sub Super Class is not visible to Sub Class+ Sub Class cannot 'ull Class+ Sub Class cannot 'ull

initiali/e its Super Class* ,#ere'ore initiali/e its Super Class* ,#ere'ore to ensure co%plete initiali/ation o' to ensure co%plete initiali/ation o' Sub Class and its Super Classes+ Sub Class and its Super Classes+ constructor is called*

constructor is called*

CA$$ basec&ass 456I7ITIO7"

CA$$ basec&ass 456I7ITIO7"

P8BIC $5CTIO7"

P8BIC $5CTIO7"

M5TO4$: constr%ctor

M5TO4$: constr%ctor IMPO+TI7' IMPO+TI7' ar1 ar1 TP5 TP5 $T+I7'"$T+I7'"

P+IA

P+IAT5 T5 $5CTIO$5CTIO7"7"

4AT

4ATA: A: >&d >&d TP5 TP5 $T+I7$T+I7'"'"

" "

" " " " " " " " " " " "" "

574CA$$"

574CA$$"

CA$$

CA$$ derivedc&ass 456I7ITIO7 derivedc&ass 456I7ITIO7 I75+ITI7' 6+OMI75+ITI7' 6+OM

basec&ass "

basec&ass "

P8BIC

P8BIC $5CTIO7"$5CTIO7"

M5TO4$:

M5TO4$: constr%ctor constr%ctor IMPO+TI7' IMPO+TI7' ar1 ar1 TP5 TP5 $T+I7'$T+I7'

ar2

ar2 TP5 TP5 $T+I7'"$T+I7'"

P+IA

P+IAT5 T5 $5CTIO$5CTIO7"7"

4AT

4ATA: A: >&d >&d TP5 TP5 $T+I7$T+I7'"'"

" "

" " " " " " " " " " " "" "

574CA$$"

574CA$$"

CA$$ derivedc&ass

CA$$ derivedc&ass IMP5M57TAIMP5M57TATIO7 "TIO7 "

M5TO4$ constr%ctor"

M5TO4$ constr%ctor"

CA

CA M5TO4 $8P5+-Fconstr%ctor M5TO4 $8P5+-Fconstr%ctor 

5PO+TI7'

5PO+TI7' ar1 ar1 E E ar1"ar1"

>&d E

>&d E ar2 "ar2 "

DDD DDD  574M5TO4"  574M5TO4" 574CA$$" 574CA$$"

$%per C&ass constr%ctor  $%per C&ass constr%ctor 

$%b C&ass constr%ctor  $%b C&ass constr%ctor 

Ca&&in $%per C&ass Ca&&in $%per C&ass

constr%ctor  constr%ctor 

(12)

Inheritance : Instance Constr%ctors !Contd"#

Inheritance : Instance Constr%ctors !Contd"#

 #et#er e!pli#et#er e!plicit call is re.uired cit call is re.uired 'or t#e instance constructor 'or t#e instance constructor o' t#e Super Class o' t#e Super Class oror not + )#en )e instantiate an object o' Sub Class is depends on t#e 'ollo)in(

not + )#en )e instantiate an object o' Sub Class is depends on t#e 'ollo)in( conditions4 conditions4 5p&icit constr%ctor is 5p&icit constr%ctor is de>ined in $%per de>ined in $%per C&assJ C&assJ 5p&icit constr%ctor is 5p&icit constr%ctor is de>ined in $%b C&assJ de>ined in $%b C&assJ

5p&icit ca&& reK%iredJ

5p&icit ca&& reK%iredJ

5 5oo 55oo 5o5o 6 6eess 55oo 5o5o 5 5oo 66eess 6e6ess 6 6eess 66eess 6e6ess

(13)

Inheritance : $tatic Constr%ctors

Inheritance : $tatic Constr%ctors

 ,#e rede'inition o' static constructor,#e rede'inition o' static constructor )ors si%ilarl to instance

)ors si%ilarl to instance constructor*

constructor*

 #en an static constructor is#en an static constructor is rede'ined t#en &898$I5I,IO5 rede'ined t#en &898$I5I,IO5 addition is not re.uired*

addition is not re.uired*

 5o para%eter inter'ace is possible '5o para%eter inter'ace is possible 'oror static constructor 1 )it# or )it#out

static constructor 1 )it# or )it#out in#eritance3

in#eritance3

 ,#e runti%e environ%ent,#e runti%e environ%ent

auto%aticall ensures t#at t#e static auto%aticall ensures t#at t#e static constructors are called in t#e ri(#t constructors are called in t#e ri(#t order+

order+ so it is so it is not re.uired to call t#enot re.uired to call t#e static constructor o' t#e Super Class static constructor o' t#e Super Class e!plicitl*

e!plicitl*

CA$$ basec&ass

CA$$ basec&ass 456I7ITI456I7ITIO7"O7"

P8BIC $5CTIO7"

P8BIC $5CTIO7"

M5TO4$:

M5TO4$: c&assconsc&assconstr%ctor"tr%ctor"

P+IAT

P+IAT5 5 $5C$5CTIO7"TIO7"

4AT

4ATA: A: >&d >&d TP5 TP5 $T+I7$T+I7'"'"

"

" " " " " " " " " " " " " ""

574CA$$"

574CA$$"

CA$$

CA$$ derivedc&ass derivedc&ass 456I7ITIO7456I7ITIO7

I75+ITI

I75+ITI7' 6+OM 7' 6+OM basec&ass "basec&ass "

P8BIC

P8BIC $5CTIO7"$5CTIO7"

M5TO4$:

M5TO4$: c&assconstr%cc&assconstr%ctor tor ""

P+IAT

P+IAT5 5 $5CTI$5CTIO7"O7"

4AT

4ATA: A: >&d >&d TP5 TP5 $T+I7$T+I7'"'"

"

" " " " " " " " " " " " " ""

574CA$$"

574CA$$"

CA$$ derivedc

CA$$ derivedc&ass IMP&ass IMP5M57TA5M57TATIO7 "TIO7 "

M5TO4$ c&assconstr%ctor" M5TO4$ c&assconstr%ctor" >&d E >&d E   I I a9 s%b a9 s%b "" DDD DDD  574M5TO4"  574M5TO4" 574CA$$" 574CA$$"

$%per C&ass constr%ctor  $%per C&ass constr%ctor 

$%b C&ass constr%ctor  $%b C&ass constr%ctor 

7o ca&& >or $%per C&ass 7o ca&& >or $%per C&ass constr%ctor 

(14)

Inheritance : Object +e>erences

Inheritance : Object +e>erences

P%b: a1< a2 P%b: a1< a2 Prot: Prot: b1< b1< b2b2  Priv:c1<c2  Priv:c1<c2 C&ass C1 C&ass C1 P%b: a1< a2<a3<a P%b: a1< a2<a3<a Prot: Prot: b1<b2<b3<bb1<b2<b3<b  Priv: c3<c  Priv: c3<c

C&ass C2 Inheritin >ro9 C1

C&ass C2 Inheritin >ro9 C1

P%b: a1<

P%b: a1< a2<a3<a<a,<a/a2<a3<a<a,<a/

Prot: Prot: b1< b1< b2<b3<b<b,<b/b2<b3<b<b,<b/ Priv:c,<c/ Priv:c,<c/ 4ATA ore>1 TP5 +56 TO C1" 4ATA ore>1 TP5 +56 TO C1" C+5AT

C+5AT5 OB=5C5 OB=5CT ore>1"T ore>1"

4ATA ore>2 TP5 +56 TO C2" 4ATA ore>2 TP5 +56 TO C2"

C+5AT5 OB=5CT ore>2" C+5AT5 OB=5CT ore>2"

4ATA ore>3 TP5 +56 TO C3" 4ATA ore>3 TP5 +56 TO C3"

C+5AT

C+5AT5 OB=5C5 OB=5CT ore>3"T ore>3" C&ass C3 Inheritin >ro9 C2

(15)

Inheritance : Object +e>erences !Contd"#

Inheritance : Object +e>erences !Contd"#

9A,A 4 ore': ,6P8 &8$ ,O C:+ 9A,A 4 ore': ,6P8 &8$ ,O C:+

ore';

ore'; ,6P8 ,6P8 &8$ &8$ ,O ,O C;*C;*

C&8A,8 OBJ8C, ore';* C&8A,8 OBJ8C, ore';* ore': < ore';* ore': < ore';* ore': -=a:* ore': -=a:* ore': -=a>* ore': -=a>* OL OL 5rror  5rror  P%b: a1< a2 P%b: a1< a2 Prot: Prot: b1< b1< b2b2  Priv:c1<c2  Priv:c1<c2 C&ass C1 C&ass C1 P%b: a1< a2<a3<a P%b: a1< a2<a3<a Prot: Prot: b1<b2<b3<bb1<b2<b3<b  Priv: c3<c  Priv: c3<c

C&ass C2 Inheritin >ro9 C1

C&ass C2 Inheritin >ro9 C1

P%b: a1<

P%b: a1< a2<a3<a<a,<a/a2<a3<a<a,<a/

Prot:

Prot: b1< b1< b2<b3<b<b,<b/b2<b3<b<b,<b/

Priv:c,<c/

Priv:c,<c/

C&ass C3 Inheritin >ro9 C2

C&ass C3 Inheritin >ro9 C2  &e'erence variables declared )it# re'erence to&e'erence variables declared )it# re'erence to a Super Class 1includin( a abstract class 3 can a Super Class 1includin( a abstract class 3 can point to an object o' a Sub Class

point to an object o' a Sub Class but canbut can on&.on&. access the co9ponents o> the object that access the co9ponents o> the object that is HnoGn to the

(16)

Inheritance : Object +e>erences !Contd"#

Inheritance : Object +e>erences !Contd"#

9A,A 4 ore': ,6P8 &8$ ,O C:+ 9A,A 4 ore': ,6P8 &8$ ,O C:+

ore';

ore'; ,6P8 ,6P8 &8$ &8$ ,O ,O C;*C;* C&8A,

C&8A,8 OBJ8C, ore': ,6P8 8 OBJ8C, ore': ,6P8 C;*C;* C&8A,

C&8A,8 OB8 OBJ8C, ore';*J8C, ore';*

ore': < ore';* ore': < ore';* ore': -=a:* ore': -=a:* ore': -=a>* ore': -=a>* OL OL OL OL P%b: a1< a2 P%b: a1< a2 Prot: Prot: b1< b1< b2b2  Priv:c1<c2  Priv:c1<c2 C&ass C1 C&ass C1 P%b: a1< a2<a3<a P%b: a1< a2<a3<a Prot: Prot: b1<b2<b3<bb1<b2<b3<b  Priv: c3<c  Priv: c3<c

C&ass C2 Inheritin >ro9 C1

C&ass C2 Inheritin >ro9 C1

P%b: a1<

P%b: a1< a2<a3<a<a,<a/a2<a3<a<a,<a/

Prot:

Prot: b1< b1< b2<b3<b<b,<b/b2<b3<b<b,<b/

Priv:c,<c/

Priv:c,<c/

C&ass C3 Inheritin >ro9 C2

C&ass C3 Inheritin >ro9 C2

4.na9ic T.pe 4.na9ic T.pe $tatic T.pe $tatic T.pe

(17)

$tatic  d.na9ic T.pe >or +e>erence

$tatic  d.na9ic T.pe >or +e>erence

 ,#e Static tpe o' ,#e Static tpe o' a re'erence variable4a re'erence variable4

 Is deter%ined usin( ,6P8 &8$ ,OIs deter%ined usin( ,6P8 &8$ ,O 

 &e%ains constant t#rou(# t#e pro(ra% &e%ains constant t#rou(# t#e pro(ra% runrun

 ,#e 9na%ic tpe o' a re'erence variable4,#e 9na%ic tpe o' a re'erence variable4

 Is deter%ined b assi(n%entIs deter%ined b assi(n%ent 

 Can c#an(e durin( pro(ra% runCan c#an(e durin( pro(ra% run

4ATA : ore>1 TP5 +56 TO C1< 4ATA : ore>1 TP5 +56 TO C1< ore>2 ore>2 TP5 TP5 +56 +56 TO TO C2<C2< ore>3 ore>3 TP5 TP5 +56 +56 TO TO C3"C3"

C+5AT5 OB=5CT ore>1 TP5 C2"

C+5AT5 OB=5CT ore>1 TP5 C2"

C+5A

C+5AT5 OB=5CT orT5 OB=5CT ore>3"e>3"

ore>1 E ore>3"

ore>1 E ore>3"

$tatic T.pe >or ore>1 is C1 $tatic T.pe >or ore>1 is C1

4.na9ic t.pe >or ore>1 is noG C2 4.na9ic t.pe >or ore>1 is noG C2

4.na9ic t.pe >or ore>1 is noG C3 4.na9ic t.pe >or ore>1 is noG C3

 In assi(n%ents o' re'erenceIn assi(n%ents o' re'erence variables +

variables + static t.pestatic t.pe o' a o' a re'erence variable is al)as re'erence variable is al)as 9ore enera& than the

9ore enera& than the d.na9ic t.pe

(18)

Inheritance : 7arroGin Cast

Inheritance : 7arroGin Cast

4ATA : ore>1 TP5 +56 TO $%per C&ass<

4ATA : ore>1 TP5 +56 TO $%per C&ass<

ore>2

ore>2 TP5 TP5 +56 +56 TO TO $%b $%b C&ass"C&ass"

ore>1 E ore>2"

ore>1 E ore>2"

 #en static tpe o' t#e tar(et variable#en static tpe o' t#e tar(et variable is %ore (eneral t#an t#e static tpe o' is %ore (eneral t#an t#e static tpe o' t#e source variable+ since t

t#e source variable+ since t#e dna%ic#e dna%ic tpe o' t#e source variable at run ti%e tpe o' t#e source variable at run ti%e can onl be %ore speciali/ed t#an its can onl be %ore speciali/ed t#an its static tpe+ t#is can be c

static tpe+ t#is can be c#eced durin(#eced durin( t#e snta! c#ec* ,#is is no)n as t#e snta! c#ec* ,#is is no)n as narroGin cast or %p cast"

narroGin cast or %p cast"

 A tp A tpical use o' narro)inical use o' narro)in( cast is to( cast is to prepare 'or

prepare 'or eneric accesseneric access* A user* A user )#o is not at all interested in t#e 'iner )#o is not at all interested in t#e 'iner points o' t#e instances o' t#e

points o' t#e instances o' t#e SubSub Classes+ but )ants to access t#e Classes+ but )ants to access t#e (eneric co%ponents 'or all o' t#e%+ (eneric co%ponents 'or all o' t#e%+ could use t#e Super Class re'erence to could use t#e Super Class re'erence to access all o' t#e% in t#e sa%e )a* access all o' t#e% in t#e sa%e )a*

7arroGin Cast 7arroGin Cast

(19)

Inheritance : Nidenin Cast

Inheritance : Nidenin Cast

4ATA : ore>1 TP5 +56 TO $%per C&ass<

4ATA : ore>1 TP5 +56 TO $%per C&ass<

ore>2

ore>2 TP5 TP5 +56 +56 TO TO $%b $%b C&ass<C&ass<

ore>3

ore>3 TP5 TP5 +56 +56 TO TO $%b $%b C&ass"C&ass"

ore>2 E ore>1" ore>2 E ore>1" ore>1 E ore>2" ore>1 E ore>2" T+" T+" ore>3 JE ore>1" ore>3 JE ore>1" CA

CATC C$MOTC C$MO5CA$T5++O+"5CA$T5++O+"

 +eact on the Cast 5rror 

 +eact on the Cast 5rror 

574T+"

574T+"

 #en static tpe o' t#e tar(et variable#en static tpe o' t#e tar(et variable is %ore speciali/ed t#an t#e static tpe is %ore speciali/ed t#an t#e static tpe o' t#e source

o' t#e source variable* ,#is is no)nvariable* ,#is is no)n as

as Gidenin cast or doGn cast"Gidenin cast or doGn cast"

 ,#e )idenin( cast in t#e later case,#e )idenin( cast in t#e later case does not cause an error because t#e does not cause an error because t#e re'erence ore': actuall points to an re'erence ore': actuall points to an instance in t#e Sub Class* 1ore': < instance in t#e Sub Class* 1ore': < ore';3

ore';3

 A tp A tpical use 'or )idenin( ical use 'or )idenin( cast is )#encast is )#en speci>ic

speci>ic co%ponents o' instancesco%ponents o' instances need to be addressed and t#eir need to be addressed and t#eir

re'erences are ept in variables t#at re'erences are ept in variables t#at are tped on t#e Super Class*

are tped on t#e Super Class*

$.nta $.nta 5rror Occ%rs 5rror Occ%rs Nidenin Cast Nidenin Cast

(20)

Inheritance : Po&.9orphis9

Inheritance : Po&.9orphis9

CA$$ s%perc&ass 456I7ITIO7"

CA$$ s%perc&ass 456I7ITIO7"

" " " " " " " " " " " " " " " " " " " " M5TO4$ test9ethod" M5TO4$ test9ethod" 574CA$$" 574CA$$"

CA$$ s%bc&assone 456I7ITIO7 I75+ITI7'

CA$$ s%bc&assone 456I7ITIO7 I75+ITI7'

6+OM s%perc&ass"

6+OM s%perc&ass"

" " " " " " " " "

" " " " " " " " "

M5TO4$ test9ethod +5456I7TIO7"

M5TO4$ test9ethod +5456I7TIO7"

574CA$$"

574CA$$"

CA$$ s%bc&asstGo 456I7ITIO7 I75+ITI7'

CA$$ s%bc&asstGo 456I7ITIO7 I75+ITI7'

6+OM s%perc&ass"

6+OM s%perc&ass"

" " " " " " " " "

" " " " " " " " "

M5TO4$ test9ethod +5456I7TIO7"

M5TO4$ test9ethod +5456I7TIO7"

574CA$$"

574CA$$"

4ATA: s%probj t.pe re> to s%perc&ass<

4ATA: s%probj t.pe re> to s%perc&ass<

 s%b1obj t.pe re> to s%bc&assone<

 s%b1obj t.pe re> to s%bc&assone<

 s%b2obj t.pe re> to s%bc&asstGo"

 s%b2obj t.pe re> to s%bc&asstGo"

$TA+T-O6-$55CTIO7"

$TA+T-O6-$55CTIO7"

C+5AT

C+5AT5 OB=5CT 5 OB=5CT s%b1obj"s%b1obj"

C+5AT

C+5AT5 OB=5CT 5 OB=5CT s%b2obj"s%b2obj"

s%probj E s%b1obj"

s%probj E s%b1obj"

CA

CA M5TO4 M5TO4 s%probj-Ftest9ethod"s%probj-Ftest9ethod"

s%probj E s%b2obj"

s%probj E s%b2obj"

 &e'erence variables declared )it# static&e'erence variables declared )it# static re'erence to a Super Class can

re'erence to a Super Class can dna%icall point to an object o' a

dna%icall point to an object o' a SubSub Class o' t#is Super Class and access Class o' t#is Super Class and access t#et#e co%ponents no)n to t#e Super Class* co%ponents no)n to t#e Super Class* Met#ods in#erited 'ro% Super Class %a Met#ods in#erited 'ro% Super Class %a be rede'ined in one or %ore o'

be rede'ined in one or %ore o' t#e Subt#e Sub Classes* ,#is is t#e basis o'

Classes* ,#is is t#e basis o' pol%orp#i

pol%orp#is% s% usin( in#eritance*usin( in#eritance*

 Pol%orp#is% #ere %eans usin( t#ePol%orp#is% #ere %eans usin( t#e sa%e na%e via sa%e inter'ace to sa%e na%e via sa%e inter'ace to uni'or%l address

uni'or%l address di''erentldi''erentl

i%ple%ented %et#ods+ belon(in( to i%ple%ented %et#ods+ belon(in( to di''erent objects o' di''erent classes in di''erent objects o' di''erent classes in t#e in#eritance tree*

(21)

4e9onstration

4e9onstration

5ercise ,: 5ercise ,:

S#o)in( #o) In#eritance )ors )it# ABAP object*S#o)in( #o) In#eritance )ors )it# ABAP object*

Objectives:Objectives: 

9e'ine Sub Classes9e'ine Sub Classes 

(22)

4e9onstration

4e9onstration

5ercise /: 5ercise /:

References

Related documents

Tento balík odporúčame kombinovať s 18-palcovými diskmi z ľahkej zliatiny Turini v čiernej matnej farbe a s dekoratívnou lištou predného nárazníka v lesklej čiernej

Table 2 in Appendix I reports descriptive statistics of various indicators such as infant mortality rate, literacy rate (total), female literacy rate, mother’s education, poverty and

For present study participants, overall appraisals of betrayal, self-blame, fear, alienation, anger, and shame fully mediated the relationship between IPV and trauma-related

The theoretical model presented in this paper reconciles empirical evidence of R&D-based innovation, R&D’s role in promoting absorptive capacity, and productivity

The compact manager is in charge of compact construction, commit of locally committed transactions (synchro- nization, permanents updates) Connected, disconnected modes

Combining gold-standard encryption technology with Kaspersky’s industry-leading anti-malware and endpoint control technologies, our integrated platform helps protect sensitive

Things that can be done by GIS in the field of regional economic development planning include: Economy geography researches, Spatial statistical analysis of economic

Schäden durch einen Wasserrohrbruch sind beispielsweise häufig derart individuell und komplex, dass sie sich derzeit nicht durch eine wie auch immer geartete künstliche