Clean Code


Listing 14-12 (continued)



Download 3,58 Mb.
Pdf ko'rish
bet219/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   215   216   217   218   219   220   221   222   ...   384
Bog'liq
Clean Code

Listing 14-12 (continued)
Args.java (After first refactoring)


231
String Arguments
After all that work, this is a bit disappointing. The structure is a bit better, but we still
have all those variables up at the top; there’s still a horrible type-case in 
setArgument
; and
all those 
set
functions are really ugly. Not to mention all the error processing. We still
have a lot of work ahead of us.
I’d really like to get rid of that type-case up in 
setArgument
[G23]. What I’d like in
setArgument
is a single call to 
ArgumentMarshaler.set
. This means I need to push
setIntArg
,
setStringArg
, and 
setBooleanArg
down into the appropriate 
ArgumentMarshaler
derivatives. But there is a problem.
If you look closely at 
setIntArg
, you’ll notice that it uses two instance variables: 
args
and
currentArg
. To move 
setIntArg
down into 
BooleanArgumentMarshaler
, I’ll have to pass
both
args
and
currentArgs
as function arguments. That’s dirty [F1]. I’d rather pass one
argument instead of two. Fortunately, there is a simple solution. We can convert the 
args
array into a 
list
and pass an 
Iterator
down to the 
set
functions. The following took me
ten steps, passing all the tests after each. But I’ll just show you the result. You should be
able to figure out what most of the tiny little steps were.
public class Args {
private String schema;
private String[] args;
private boolean valid = true;
private Set unexpectedArguments = new TreeSet();
private Map marshalers = 
new HashMap();
private Set argsFound = new HashSet();
private 

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   215   216   217   218   219   220   221   222   ...   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