Game Development Reference
In-Depth Information
[d]oIkjau9>]jg*ceraIkjauPk?heajp7
y
y
In the preceding example, the ceraIkjauPk?heajp variable is declared as lq^he_ but
also op]pe_ . If you declare a variable as op]pe_ , you can access that variable from any
other class using this format:
?h]ooJ]ia*r]ne]^haJ]ia
Methods can also be declared as op]pe_ . In the previous chapter, the ^hk_g method of
the ?khheoekj class was declared as op]pe_ , so you could access the method from the
I]ej class in this way:
?khheoekj*^hk_g$k^fa_pKja(k^fa_pPsk%7
You would not typically define cap methods as op]pe_ , but I've done so here to make
the examples a littler clearer.
The properties are now private. But this directive is the most important change:
[d]oIkjau9>]jg*ceraIkjauPk?heajp7
It's no longer directly changing one of the bank's properties. Instead, it's accessing a cap method in the
>]jg class called ceraIkjauPk?heajp. It doesn't make any presumptions about whether the response
from the bank will be pnqa or b]hoa; it simply requests this information from the bank. Whatever it
finds will be referenced in the client's [d]oIkjau property. It will be pnqa if the client has money and
b]hoa if there's no money.
This is what the new >]jg class looks like, featuring the ceraIkjauPk?heajp's cap method:
lq^he__h]oo>]jg
w
lner]par]n[_heajpD]oIkjauEj=__kqjp9b]hoa7
lq^he_op]pe_bqj_pekjcapceraIkjauPk?heajp$%6>kkha]j
w
eb$[_heajpD]oIkjauEj=__kqjp%
w
napqnjpnqa7
y
ahoa
w
napqnjb]hoa7
y
y
y
 
Search Nedrilad ::




Custom Search