SlideShare a Scribd company logo
1 of 9
Download to read offline
Proxy
Proxy パターン
クラス図
Decorator パターンと
    似てるね!
//Proxy Pattern
public class Proxy implements Subject{
    private Subject subject;
    public Proxy(){
        subject = new RealSubject();
    }
    public void doAction(){
        ...;
        subject.doAction();
        ...;
    }
}

//client for Proxy
public class Client{
    public static void main(String[] args){
        //the client doesn’t know the Proxy
        //delegate another object
        Subject subject = new Proxy();
        ...;
    }
}
Proxy パターン
●   Decorator パターンと似てるけど違うよ
    ●   Decorator は移譲オブジェクトへの機能の追加
●   Proxy は移譲オブジェクトへのアクセスをコン
    トロール
●   Proxy は移譲オブジェクトをクライアントへ露
    出させない
Proxy パターンの細かい種類
●   Virtual Proxy
    ●   主にリソースを食う移譲オブジェクトの遅延初期
        化や使い回し (Flyweight) など
●   Remote Proxy
    ●   隠れてこそこそリモート通信するやつ
●   Access Proxy
    ●   アクセス制限など
●   Smart Proxy
    ●   Decorator パターンのこと
Java EE におけるプロキシ
●   JNDI から取得できるコンポーネントは大抵全
    部プロキシ
    ●   java.sql.Connection
    ●   javax.jms.Connection
    ●   EJB
●   Java EE ではこれらのプロキシオブジェクト
    たちハンドル、スタブと呼ばれる
java.lang.reflect.Proxy
●   ダイナミックプロキシを作ることができる
    ●   プロキシ対象クラスが事前にわからない場合に使
        う
InvocationHandler handler = new MyInvocationHandler(...);
Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
                                     new Class[] { Foo.class },
                                     handler);

More Related Content

More from nekop (9)

Java Drag Race Tuning
Java Drag Race TuningJava Drag Race Tuning
Java Drag Race Tuning
 
JBoss AS 7 / EAP 6 modules and class loading
JBoss AS 7 / EAP 6 modules and class loadingJBoss AS 7 / EAP 6 modules and class loading
JBoss AS 7 / EAP 6 modules and class loading
 
JBoss AS7 rev3
JBoss AS7 rev3JBoss AS7 rev3
JBoss AS7 rev3
 
Infinispan - Open Source Data Grid rev2
Infinispan - Open Source Data Grid rev2Infinispan - Open Source Data Grid rev2
Infinispan - Open Source Data Grid rev2
 
JBoss AS7
JBoss AS7JBoss AS7
JBoss AS7
 
CDI, Seam 3 and Forge
CDI, Seam 3 and ForgeCDI, Seam 3 and Forge
CDI, Seam 3 and Forge
 
Infinispan - Open Source Data Grid
Infinispan - Open Source Data GridInfinispan - Open Source Data Grid
Infinispan - Open Source Data Grid
 
Iteratorパターン
IteratorパターンIteratorパターン
Iteratorパターン
 
ClassLoader Leak Patterns
ClassLoader Leak PatternsClassLoader Leak Patterns
ClassLoader Leak Patterns
 

Recently uploaded

Recently uploaded (10)

Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 

Proxy

  • 4. Decorator パターンと 似てるね!
  • 5. //Proxy Pattern public class Proxy implements Subject{ private Subject subject; public Proxy(){ subject = new RealSubject(); } public void doAction(){ ...; subject.doAction(); ...; } } //client for Proxy public class Client{ public static void main(String[] args){ //the client doesn’t know the Proxy //delegate another object Subject subject = new Proxy(); ...; } }
  • 6. Proxy パターン ● Decorator パターンと似てるけど違うよ ● Decorator は移譲オブジェクトへの機能の追加 ● Proxy は移譲オブジェクトへのアクセスをコン トロール ● Proxy は移譲オブジェクトをクライアントへ露 出させない
  • 7. Proxy パターンの細かい種類 ● Virtual Proxy ● 主にリソースを食う移譲オブジェクトの遅延初期 化や使い回し (Flyweight) など ● Remote Proxy ● 隠れてこそこそリモート通信するやつ ● Access Proxy ● アクセス制限など ● Smart Proxy ● Decorator パターンのこと
  • 8. Java EE におけるプロキシ ● JNDI から取得できるコンポーネントは大抵全 部プロキシ ● java.sql.Connection ● javax.jms.Connection ● EJB ● Java EE ではこれらのプロキシオブジェクト たちハンドル、スタブと呼ばれる
  • 9. java.lang.reflect.Proxy ● ダイナミックプロキシを作ることができる ● プロキシ対象クラスが事前にわからない場合に使 う InvocationHandler handler = new MyInvocationHandler(...); Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(), new Class[] { Foo.class }, handler);