Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet160/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   156   157   158   159   160   161   162   163   ...   384
Bog'liq
Clean Code

Java Proxies
Using persistence as an example, you would declare which objects and attributes (or
patterns
thereof) should be persisted and then delegate the persistence tasks to your persis-
tence framework. The behavior modifications are made 
noninvasively
8
to the target code
by the AOP framework. Let us look at three aspects or aspect-like mechanisms in Java.
Java Proxies
Java proxies are suitable for simple situations, such as wrapping method calls in individual
objects or classes. However, the dynamic proxies provided in the JDK only work with
interfaces. To proxy classes, you have to use a byte-code manipulation library, such as
CGLIB, ASM, or Javassist.
9
Listing 11-3 shows the skeleton for a JDK proxy to provide persistence support for
our
Bank
application, covering only the methods for getting and setting the list of accounts.
8.
Meaning no manual editing of the target source code is required.
9.
See [CGLIB], [ASM], and [Javassist].
Listing 11-3 
JDK Proxy Example
// Bank.java (suppressing package names...)
import java.utils.*;
// The abstraction of a bank.
public interface Bank {
Collection getAccounts();
void setAccounts(Collection accounts);
}
// BankImpl.java
import java.utils.*;
// The “Plain Old Java Object” (POJO) implementing the abstraction.
public class BankImpl implements Bank {
private List accounts;
public Collection getAccounts() { 
return accounts; 
}
public void setAccounts(Collection accounts) { 
this.accounts = new ArrayList(); 
for (Account account: accounts) {
this.accounts.add(account);
}
}
}
// BankProxyHandler.java
import java.lang.reflect.*;
import java.util.*;


162

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   156   157   158   159   160   161   162   163   ...   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