BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage Guides Dynamic Proxies in Java Mini-Book

Dynamic Proxies in Java Mini-Book

Bookmarks

Of all the things that we could learn this month, why dynamic proxies?

Back in 1996, we could learn the entire Java ecosystem in a week with Bruce Eckel's "Thinking in Java".

Fast-forward to 2020 and the volume of information is overwhelming.

Java is still quite easy to learn, especially if we focus on the most essential tools. Start with the syntax, then object-orientation, flow control, collections and Java 8 streams. Design patterns hold everything together.

But there is more, much more.

To become a true Java Specialist, we need to also master the underpinnings of this great platform. How else can we develop systems that take advantage of the power of Java?

Dynamic proxies are such a tool. We can save thousands of lines of repetitive code with a single class. By taking a thorough look at how they work, we will recognize good use cases for them in our systems.

Dynamic proxies are not an everyday tool. They may come in handy only half a dozen times in our careers. But when they fit, they save us an incredible amount of effort. I once managed to replace over half a million code statements with a single dynamic proxy. Powerful stuff.

This book is for intermediate to advanced Java programmers who want to get to "guru" status. It is not suitable for beginners in Java.

We hope you enjoy this book as much as I enjoyed writing it for you!

Let the dynamic proxy games begin!

Free download

Table of Contents:

  • Preface
    • Big win 
    • Infrastructure code 
    • But wait… 
    • What will we learn?
    • TL;DR? 
    • Java version 
    • Enjoy!
  • Design-Patterns Cousins 
    • Proxy pattern
    • Adapter pattern 
    • Decorator pattern
    • Composite pattern 
    • Chain-of-responsibility pattern
  • Handcrafted Proxies 
    • Lazy initialization with virtual proxy 
    • Calling remote methods with remote proxy 
    • Security with the protection proxy 
    • Cascaded proxies 
    • Implementing equals() in proxies 
  • Dynamic Proxy 
    • Proxy.newProxyInstance() 
    • InvocationHandler
    • Name of dynamic class 
    • Dissecting $Proxy. 
    • Turbo-boosting reflection methods 
    • Unwrapping the InvocationTargetException 
    • Casting. 
    • Virtual dynamic proxy 
    • Synchronized dynamic proxy 
    • EnhancedStream with dynamic proxies 
    • Restrictions with dynamic proxies 
    • Performance of dynamic proxies
  • Dynamic Decorator 
    • Decorator design pattern 
    • Using dynamic proxy to implement filter 
    • VTable 
    • ChainedInvocationHandler
  • Dynamic Object Adapter
    • Rapper wrappers 
    • A better ArrayList 
    • BetterCollection interface. 
    • Dynamic object adapter using dynamic proxies 
    • Restrictions of adapter 
    • Performance of dynamic-object-adapter method calls
  • Dynamic Composite 
    • Contact, Person, and DistributionList
    • Hacking dynamic proxy for composites
    • AppendableFlushableCloseable 
       
BT