Clean Code


public void set(String s) {



Download 3,58 Mb.
Pdf ko'rish
bet208/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   204   205   206   207   208   209   210   211   ...   384
Bog'liq
Clean Code

public void set(String s) {
booleanValue = true;
}
}
And finally I replaced the call to 
setBoolean
with a call to 
set
.
private void setBooleanArg(char argChar, boolean value) {
booleanArgs.get(argChar)
.set("true");
}
The tests all still passed. Because this change caused 
set
to be deployed to the 
Boolean-
ArgumentMarshaler
, I removed the 
setBoolean
method from the 
ArgumentMarshaler
base
class.
Notice that the abstract 
set
function takes a 
String
argument, but the implementation
in the 
BooleanArgumentMarshaller
does not use it. I put that argument in there because I
knew that the 
StringArgumentMarshaller
and 
IntegerArgumentMarshaller
would
use it. 


218
Chapter 14: Successive Refinement
Next, I wanted to deploy the 
get
method into 
BooleanArgumentMarshaler
. Deploying
get
functions is always ugly because the return type has to be 
Object
, and in this case
needs to be cast to a 
Boolean
.
public boolean getBoolean(char arg) {
Args.ArgumentMarshaler am = booleanArgs.get(arg);
return am != null && 
(Boolean)
am.
get
();
}
Just to get this to compile, I added the 
get
function to the 
ArgumentMarshaler
.
private abstract class ArgumentMarshaler {
...
public Object get() {
return null;
}
}
This compiled and obviously failed the tests. Getting the tests working again was simply a
matter of making 
get
abstract and implementing it in 
BooleanAgumentMarshaler
.
private abstract class ArgumentMarshaler {
protected boolean booleanValue = false;
...
public 
abstract
Object get();
}
private class BooleanArgumentMarshaler extends ArgumentMarshaler {
public void set(String s) {
booleanValue = true;
}

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   204   205   206   207   208   209   210   211   ...   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