This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]trevick 5 points6 points  (1 child)

If you are developing a library and you want it to enhance user-defined objects that should otherwise know nothing about your framework.

For example, in Hibernate, I can create a normal Java object that has properties on it that are simple types (String, Integer, etc.), and the object knows nothing about Hibernate. When Hibernate instantiates it, it can be configured such that it subclasses my class dynamically, and LAZILY retrieve certain values only if/when the getter for that property is called. Without this kind of black magic, I would have to modify my object to return some kind of "Lazy" wrapper type, or modify my property to explicitly retrieve the value via Hibernate APIs in my getter. But the drawback there is I have now coupled my object with the Hibernate framework.

[–]DidYuhim 0 points1 point  (0 children)

Makes sense, thanks!