Skip to content

A quick "how does this work" thing to make me understand how dynamic proxy interfaces can wrap other classes and auto-convert parameters.

License

Notifications You must be signed in to change notification settings

JannuMies/poc-proxyer-thingy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pox-proxyer-thingy

A quick "how is this done" thing to understand dynamic proxying.

I wanted to understand how to go from manually writing a wrapper to dynamically creating a wrapper from an interface and a wrapped implementation. So instead of having this:

public class FoodShop {
  Pastry getFood(Pound money) {
      Euro euro = new Euro();
      euro.setValue(money.getValue() * 0.8);
      
      StrudelShop strudelShop = new StrudelShop();
      Strudel strudel = strudelShop.getFood(euro);
      
      Pastry pastry = new Pastry();
      pastry.setName(strudel.getName());
      pastry.setPrice(strudel.getPrice());
      return pastry;
  }
}

to this;

public interface FoodShop {
  Pastry getFood(Pound money);
}

used with:
  FoodShop proxyedFoodStore = proxyer.getInstance(FoodShop.class);
  Pastry pastry = proxyedFoodStore.getFood(new Pound(1.35));

About

A quick "how does this work" thing to make me understand how dynamic proxy interfaces can wrap other classes and auto-convert parameters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages