— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet95/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   91   92   93   94   95   96   97   98   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

class ElectricGuitar {
String brand;
int numOfPickups;
boolean rockStarUsesIt;
String getBrand() {
return brand;
}
void setBrand(String aBrand) {
brand = aBrand;
}
int getNumOfPickups() {
return numOfPickups;
}
void setNumOfPickups(int num) {
numOfPickups = num;
}
boolean getRockStarUsesIt() {
return rockStarUsesIt;
}
void setRockStarUsesIt(boolean yesOrNo) {
rockStarUsesIt = yesOrNo;
}
}
Note: Using these 
naming conventions 
means you’ll be 
following an 
important Java 
standard!


80
 
chapter 4
Jen says you’re 
well-encapsulated...
Encapsulation
Do it or risk humiliation and 
ridicule.
Until this most important moment, we’ve 
been committing one of the worst OO 
faux pas (and we’re not talking minor 
violation like showing up without the ‘B’ 
in BYOB). No, we’re talking Faux Pas with 
a capital ‘F’. And ‘P’.
Our shameful transgression?
Exposing our data!
Here we are, just humming along without 
a care in the world leaving our data out 
there for anyone to see and even touch.
You may have already experienced that 
vaguely unsettling feeling that comes with 
leaving your instance variables exposed.
Exposed means reachable with the dot 
operator, as in:
theCat.height = 27;
Think about this idea of using our remote 
control to make a direct change to the Cat 
object’s size instance variable. In the hands 
of the wrong person, a reference variable 
(remote control) is quite a dangerous 
weapon. Because what’s to prevent:

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   91   92   93   94   95   96   97   98   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish