Clean Code


new BooleanArgumentMarshaler()



Download 3,58 Mb.
Pdf ko'rish
bet204/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   200   201   202   203   204   205   206   207   ...   384
Bog'liq
Clean Code

new BooleanArgumentMarshaler()
);
}
..
Listing 14-11
ArgumentMarshaller appended to Args.java
private class ArgumentMarshaler {
private boolean booleanValue = false;
public void setBoolean(boolean value) {
booleanValue = value;
}
public boolean getBoolean() {return booleanValue;}
}
private class BooleanArgumentMarshaler extends ArgumentMarshaler {
}
private class StringArgumentMarshaler extends ArgumentMarshaler {
}
private class IntegerArgumentMarshaler extends ArgumentMarshaler {
}
}


214
Chapter 14: Successive Refinement
private void setBooleanArg(char argChar, boolean value) {
booleanArgs.
get
(argChar)
.setBoolean
(value);
}
...
public boolean getBoolean(char arg) {
return falseIfNull(booleanArgs.get(arg).
getBoolean()
);
}
Notice how these changes are in exactly the areas that I mentioned before: the 
parse
,
set
, and 
get
for the argument type. Unfortunately, small as this change was, some of the
tests started failing. If you look carefully at 
getBoolean
, you’ll see that if you call it with
'y
,
'
but there is no 
y
argument, then 
booleanArgs.get('y')
will return 
null
, and the func-
tion will throw a 
NullPointerException
. The 
falseIfNull
function had been used to protect
against this, but the change I made caused that function to become irrelevant.
Incrementalism demanded that I get this working quickly before making any other
changes. Indeed, the fix was not too difficult. I just had to move the check for 
null
. It was
no longer the 
boolean
being
null 
that I needed to check; it was the 
ArgumentMarshaller
.
First, I removed the 
falseIfNull
call in the 
getBoolean
function. It was useless now, so
I also eliminated the function itself. The tests still failed in the same way, so I was confi-
dent that I hadn’t introduced any new errors. 
public boolean getBoolean(char arg) {
return booleanArgs.get(arg).getBoolean();
}
Next, I split the function into two lines and put the 
ArgumentMarshaller
into its own vari-
able named 
argumentMarshaller
. I didn’t care for the long variable name; it was badly
redundant and cluttered up the function. So I shortened it to 
am
[N5]. 
public boolean getBoolean(char arg) {
Args.ArgumentMarshaler 

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   200   201   202   203   204   205   206   207   ...   384




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