Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few alternatives, although none are very nice</p> <ol> <li><p>Make the wrapper implement the interface, if it's known at compile time if the wrapped object also implements the interface. A factory method can be used to create the wrapper if it is not known until runtime if the wrapped object will implement the interface. This means you then have separate wrapper classes for the possible combinations of implemented interfaces. (With one interface, you need 2 wrappers, one with and one without. For 2 interfaces, 4 wrappers and so on.)</p></li> <li><p>Expose the wrapped objects from the wrapper, so that clients can walk the chain and test each object in the chain for the interface using <code>instanceof</code>. This breaks encapsulation.</p></li> <li><p>Have a dedicated method to retrieve the interface, implemented by both the wrapper and the wrapped object. E.g. <code>asSomeInterface()</code>. The wrapper delegates to the wrapped object, or creates a proxy around the wrapped object to preserve encapsulation.</p></li> <li><p>Create one wrapper class for each interface - the wrapper is implemented as usual - it implements the interface and delegates to another implementation of that interface. A wrapped object may implement several interfaces so several wrapper instances are combined into one logical instance by using a dynamic proxy to delegate the interface methods implemented by the proxy to the appropriate wrapper instance. It's necessary that the set of interfaces implemented by the proxy do not have any method signatures in common. </p></li> </ol> <p>Microsoft baked <a href="http://msdn.microsoft.com/en-us/library/ms686558%28VS.85%29.aspx" rel="nofollow noreferrer">aggregation</a> (<a href="http://msdn.microsoft.com/en-us/library/ms686558%28VS.85%29.aspx" rel="nofollow noreferrer">Wikipedia</a>) into their Component Object Model (COM). It appears to be unused by the majority yet results in considerable complexity for COM object implementors, since there are rules that every object must adhere to. Wrapped objects are encapsulated by having wrapped objects know about they're wrappers, having to maintain a pointer to the wrapper, which is used when implementing QueryInterface (loosely <code>instanceof</code>) for the exposed public interfaces - the wrapped object returns the interface implemented on the wrapper rather than it's own implementation. </p> <p>I've not seen a clean, easy to understand/implement and correctly encapsulated solution to this. COM aggregation works and provides complete encapsulation, but it's a cost you pay for every single object you implement, even if it is never used in an aggregate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload