Wrapper/Proxy pattern

Hi,
We�re in the process of updating one of our APIs, which contains lots of interfaces (backed by heavyweight implementations - the java.sql package is a good comparison). I want to help vendors to wrap our existing implementations so that they can add extra functionality without having to re-implement all the backend workings by providing a "wrappers" package, which simply passes (unwrapped) arguments to the underlying implementations, and wraps returned heavyweights coming back up, allowing the vendors to add small amounts of functionality where needed.
// interfaces, could be heavyweight or wrappers..
interface Foo {
    Bar getBar(Hee theHee);
interface Bar {
   Foo getFoo();
// wrappers
class FooWrapper implements Foo {
     private final Foo myWrapped;
     public FooWrapper(Foo theWrapped) {
          this.myWrapped = theWrapped;
     public Bar getBar(Hee theHee) {
          return new BarWrapper(this.myWrapped.getBar(theHee));
class BarWrapper implements Bar {
     private final Bar myWrapped;
     public BarWrapper(Bar theWrapped) {
          this.myWrapped = theWrapped;
     public Foo getFoo() {
          return new FooWrapper(this.myWrapped.getFoo());
}The first issue I had with this was the calling new XxxWrapper is patently bum, as it means that the methods have to be overridden anyway to stop the "default" XxxWrappers from being returned. This, in my opinion, is easily solved by using a WrapperFactory, which can be passed in during construction of the wrapper, and called where needed to allow the user to supply there own wrapper implementations.
The second issue involves "unwrapping" which I am unsure as to the best way forward. In the, as yet undisclosed, "Hee" we should really have unwrapped it before passing it to the underlying Foo, otherwise it will still be the wrapped version of the Hee, (assuming) HeeWrapper. This is where the questions arise.
-What happens if it's not a HeeWrapper? My Initial thoughts are throw an exception, as, assuming it's come from our provider/factory, it should have been wrapped by us before the user could have gotten hold of it. Unless of course the WrapperFactory isn't returning HeeWrappers for some reason?
-What�s the best way to unwrap it? Again, initially I thought of adding an unwrapXxx to the WrapperFactory and let the user deal with it, though this seems to add too many methods. I also thought about WrapperFactory.unwrap(Object) letting the provider unwrap it generically and then casting the results? I avoided adding a Hee.unwrap() method in case it could lead to mistakenly unwrapping other providers (who are also using the wrappers package) implementations, though this may be a bit anal, but I�m sure I could abuse it (and therefore others no doubt could), so I want to avoid it.
-What happens if the Hee originates from the underlying implementation, say via an event? Delegate the wrapping of that Hee to the factory again? Should the default factory cache the results to allow the same wrapper to be returned each time, or just create a new one?
Has anyone done anything like this, or have any obvious solutions that I've missed, or just some preference?

So what you want to do with wrappers is beyond me.
Why do you not want to use abstract classes? What problem do you think is going unsolved in that case?I might be misunderstanding the problem but it's been while since prefer "composition to extension" became a mantra.
Suppose you have a type Foo. And you have behaviors Up and Down you wish to implement:
UpFoo
DownFoo
But wait, what if up and down aren't mutually exclusive (OK I could have chosen better names here.)
UpDownFoo
Great. Now here come Charm and Strange. So let's add:
CharmFoo
StrangeFoo
Now the combos:
UpCharmFoo
DownCharmFoo
UpStrangeFoo
DownStrangeFoo
UpDownCharmFoo
UpDownStrangeFoo
CharmStrangeFoo
UpCharmStrangeFoo
DownCharmStrangeFoo
UpDownCharmStrangeFoo
Whew. That was a lot of classes to write. I hope I didn't miss any. Uh oh, here come Top and Bottom...
I'm not going to type these out. Suffice it to say that this is an unsustainable approach. A good example of this approach is the Collections class which provides A synchronized wrapper and a unmodifiable wrapper so that we don't end up with all the permutations with all the map implementations.
This is usually called the Decorator pattern and it has been considered before. It's in the GoF.

Similar Messages

  • [svn:fx-trunk] 11250: Fixing proxy pattern bug in VideoPlayer.

    Revision: 11250
    Author:   [email protected]
    Date:     2009-10-28 17:07:19 -0700 (Wed, 28 Oct 2009)
    Log Message:
    Fixing proxy pattern bug in VideoPlayer.  I tried to save a few extra bytes by not keeping around an extra object, but I made a mistake with this code.  It seems better just to follow the typical pattern and not worry about this extra savings, which probably cost more in code-size anyways. 
    Also changing VideoPlayer.thumbnailSource to mx_internal, rather than public.  In VideoElement it's mx_internal, and that's what it should be here too.
    QE notes: -
    Doc notes: -
    Bugs: SDK-23665
    Reviewer: Deepa
    Tests run: checkintests, mustella VideoPlayer
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-23665
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/VideoPlayer.as

  • Difference between Proxy pattern and Business Delegate pattern

    Hi All,
    Can any one please tell me what is the difference between Proxy pattern and Business Delegate pattern.
    Thanks in advance.
    Basak

    The books they were first reported in, and the expressed intent, I guess. Arguably, the Business Delegate pattern is a special case Proxy, with more specific details about what resource is being proxied

  • Generic Proxy pattern - help needed.

    Greetings!
    Lately i have been working on some design architecture to work on possible ways of designing message flows in OSB.
    I found one excellent solution called Generic Proxy pattern at: http://javamaster.wordpress.com/tag/osb/ .
    This pattern consists of four proxy services.
    Actually Generic Proxy pattern and proxy service are different. You can read more about pattern at : http://game-engineering.blogspot.com/2010/03/adapter-pattern-vs-proxy-pattern.html
    My problem is interesting and very straight forward.
    1. I have one proxy service which is created on client side WSDL.
    2. I have one business service created on legacy system WSDL.
    Now, if i want to implement this Generic Proxy pattern, I need to create two more proxy services in between my existing proxy service & existing business service.
    On what basis should these two proxy services should be created?
    Options in OSB to create a proxy service are : WSDL Web Service / Messaging Service / Any SOAP Service / Any XML Service / Business Service / Proxy Service
    If anybody has worked in this pattern, please help.
    Any inputs from everyone are welcome.
    Thanks and Regards,
    Swapnil Kharwadkar.

    The generic proxy service will be of type "messaging service" with input/output type as text/XML.

  • Proxy Pattern

    Hi all,
    I've been reading about the Proxy Pattern and it seems like just normal encapsulation to me or do I misunderstand it?
    To me, Proxy looks like using a "middleman" class to delegate requests to the actual class so that the implementation of the actual class is hidden from the user.
    Another benefit of this proxy pattern is that can delay the creation of an object from the actual class until you need it.
    That is what I understand from what I read about it, but do you know some scenarios where you would use the proxy pattern?
    Is it for example useful to separate the GUI from the actual code?
    grtz

    The Business Delegate design pattern is a version of the Proxy pattern.
    A Presentation-tier Business Delegate delegates method calls to the Business tier.
    The code on the Presentation tier only contains references to the business delegate. There are no class/code level dependencies between the business model implementation and the code on the Presentation tier.

  • Proxy design pattern

    Hey,
    I have jar that run in different enviroments (client,server,partners).
    In my jar i have some method that in case they called the action that executed is depend on the implementor.
    For example let say that i have method "updateXXX(long id,String name){
    Notify.notify(...)
    if this called in the client than it need to lookup to this service and send the class name, method name and the method parameters to the service.
    if it run in the server than it need to run XXX with the same parameters (this infrastrcture need to server some method with different parameters).
    Is the proxy design patterns is the solution for this?
    I thought to demand from each imlementor that want to use those kind of methods to implement a plugin with a given class name and in notify to load this class with class.forName, what are you say about this soultion?
    any other ideas will be more than welcome.

    The proxy pattern could help here, but isn't the simplest solution. You just want to define an interface that has those updateXXX methods declared on it, and have several classes implement those methods, such as one which executes some code in the same process, or one that does so over RMI, that sort of thing. Write your calling code against that interface, and configure at runtime which class they'll be calling
    interface Updater {
        void updateXXX(Object params);
    class LocalUpdater implements Updater {
         public void updateXXX(Object params) {
           // code to do work here
    class RemoteUpdater implements Updater {
    public void updateXXX(Object params) {
           // code to do remote work here
    class Client {
       Updater myUpdater;
       Client(Updater updater) { // constructor takes an instance of something which implements Updater
           myUpdater = updater;
        void doSomething() {
           myUpdater.updateXXX("params"); // see how this class is decoupled from your Updater implementations
    }How you inject your concrete dependencies is up to you.

  • Proxy design pattern help

    Hi,
    Could please clarify my below doubts on proxy design pattern?
    There are several cases where a Proxy can be useful:
    *1. If the object is on a remote machine and loading it over the network may*
    be slow, especially during peak network load periods.
    so In this case how do we get the object which is in remote? By copying the jar files from the server to client
    is that right?So we will get the object which is in the remote.
    *2. If the object has limited access rights, the proxy can validate the access*
    permissions for that user.
    This how do we do?
    Thanks
    Bhanu

    Hi Paratheosis ,
    I almost got the point. But what I have heard about proxy pattern is, we use proxy to reduce the traffic between
    client and server. In this case whenever we need any method on the server side we call isnt?..how trafic is being reduced here? Or is it storing somewhere client when we first time access the Object in Server side? for example
    In Servicemanager getEmployeedetails.. So in client do we store the ServiceManager object so that next time we can access the that ServiceManager object in the client side.. Is it in this way? I dont think because any updation on the ServiceManager will not be able to get in the client side? I totally confused the implements for proxy.. :(
    Thanks
    Bhanu.

  • Proxy business services in osb

    In osb if i want to get data from a client then what is the procedure
    I am using a business service whose endpointuri is a proxy service (protocol http)
    And this business service is inturn called by my local proxy service
    Is this procedure correct ?
    if not then what is the correct procedure how many proxy and business services do i need to get data from my client
    Thanks,
    Rahul

    How many Proxy Services and Business Services to use depends on the use case.
    For example, if your client will initiate a transaction when it has some data to send to another system then you will have to configure following flow:
    First system (wants to send some data)--> Proxy Service(to receive data from Client) --> Business Service (to call the second system) --> second system web service API
    Another scenario in which you need to get some data from the second system when requested by the first system (query scenario) the above flow would still remain the same.
    Addition of another Proxy service depends on specific use case and scope of re-usability etc. For example if you want to fetch data from a system and that query can be reused in various processes or can also be called from various client applications then you can create a wrapper Proxy above the Business service and call this Proxy Service instead of calling the business service from your Proxy.
    Domain structure also is a deciding factor, for example if you want to call a Proxy in one domain from another domain you can use a Business Service in the requesting domain.

  • Design patterns in log4j

    hi
    i have a question that was asked to me
    what pattern does log4j appender(consoleappender,rollingfileappender etc) implement?
    candidates can be dao, facade etc....
    can somebody xplain what pattern does it use and how
    techy

    actually this question was given in an exam and the
    answer that the teacher gave was proxy pattern.Actually, if you think about it, only the individuals that programmed the log4j code know what design patterns they actually used.
    As an outsider, just because an application "looks" like a pattern might have been used, does not mean it was actually used to design the application.
    Futhermore, just because an application's functionality may fit in well with how one envisions the pattern's possible implementation, this too, does automatically equate or represent the fact that the pattern(s) were used.
    This is a poor question to have on an exam, especailly if the individuals taking the exam were not the ones that worked on log4j. If the exam was given to log4j programmers, then it is a reasonable question.
    To ask this question to assess knowledge/experience with log4j or object-oriented design patterns is a bad decision, in my opinion.
    Only close and detailed inspection of the log4j source code will reveal what design patterns were actually used. Again, to question someone on this is inappropriate, unless it is for the log4j development team, in my opinion.
    i m not able to understand how it applies proxy
    pattern?I understand your confusion.

  • Proxy for Basic Authentication

    Hi,
    Can someone point out if I am on the right track about this ?
    I have an application which uses Basic Authentication as its authentication mechanism.I have defined the Application for single sign-on using the External Applications option in the Portal Builder.
    I have read further down in the documentation (Configuring and Administering External Applications) http://download.oracle.com/docs/cd/B10464_01/manage.904/b10851/ext_apps.htm#1009009
    that there is something called Proxy Authentication for Basic Authentication Applications.
    Can someone explain this to me as I am unsure as to whether I need to set this proxy up as well ? The diagram in the documentation appears to be what I am trying to do.
    As I mentioned in a previous post Basic Authentication doesn't appear to be working for me. The very first time I authenticate I get straight into the application but any attempts after that results in the Basic Authentication dialog box appearing even though I have checked the "Remember my login information" tick box.
    Any ideas ?
    Thanks,

    Thank you for the response. I tried with a pass-through service account but could not get it working.
    This is what I did:
    1. I have a SOAP business service with WS-Policy with username security assertion.
    2. I created a SOAP business service with the wsdl. OSB EPE editor said OSB does not support WSSE 1.2 policies. I extended my OSB domain to include OWSM and in the business service policy tab, selected OWSM policy option and added "oracle/wss_username_token_client_policy". (Now I am not sure how the user credentials in HTTP BASIC (headers) will be propagated to WS-Security headers)
    3. I created a pass through service account and added this service account in the SOAP business service. I am able to configure service account only when I choose HTTP BASIC authentication in the business service. This did not propagate the username from HTTP to WS-Security. I see errors in the log like "WSM-00015 : The user name is missing.". Looks like wss_username_token_client_policy is looking for username in csf-key map. I do not know this map gets populated internally. If I have to do it programmatically I saw there is java code to set BindingProvider.USER_NAME in the request context. How do I do this from OSB designer ?
    4. I tried creating a wrapper proxy around the secure SOAP business service and include the wrapper proxy in my main proxy but could not get it working. I get lof of NullPointers.
    I am missing something. Can you please help ?

  • Pattern b/w Remote interface & Container implementation  class

    Which pattern is followed by EJB Remote interface & Container implementation class of that interface?Is there anyting mentioned in specs?
    This questoin was asked to me by many people.I think it is Command design pattern as it hides away all the details of actual business implementation.but at same time I doubt if it is Facade?
    Anyone who knows about this?
    Thanx in advance
    Sidhu

    Rarely is software represent a single pattern, it typically represents multiple patterns.
    Which pattern is followed by EJB Remote interfaceThe remote interface is an example of a facade pattern. This presents a public interface which is an abstraction of the real interface.
    Container implementation class of that interface? The implementation is an example of what I think of as a double proxy pattern. That is acting as two distinct proxies. The first being the the remote callingof EJB standard functions via the Skelton implementation. I.E. The underlying EJB/RMI interface. The Second being a application level proxying of the business logic seen in most RL implementation.
    The use of an UID ID beans is an example of a memento.
    I think it is Command design pattern as it hides away all the
    details of actual business implementation.Not directly, though an AppServer programmer may use the Command Pattern to resolve the remote connections. The User Application Programmer may also use this pattern. The key element of Command Pattern is the Invoker executing an concrete class via abstraction or interface of a polymorphic class. You can think of this as a specialisation of the
    Martin

  • Business delegate pattern doubt

    Hi,
    One of the reasons for going for Business delegate pattern is because the business components is vulnerable to changes.
    Suppose if the business component has a method
    getAccountInfo( int Accountnumber)
    The business delegate pattern may have a method
    getAccountInfoFromBusiness(Accountnumber int)
    return businesscomponent.getAccountInfo(Accountnumber);
    and the presentation tier components will have code containing invoking to getAccountInfoFromBusiness method.
    Now suppose if business component method signature changes then the signature of business delegate class will also change. This turn in requires changes to presentation tier components. I really dont understand why business delegate pattern is needed.

    Hi,
    One of the reasons for going for Business delegate
    pattern is because the business components is
    vulnerable to changes.Abstraction is your first tool to reduce a projects exposure to change.
    Secondly filling you code with getter and setters is a bad idea, it's procedural not OO, Objects should express themselves.
    So instead of :
    Suppose if the business component has a method
    getAccountInfo( int Accountnumber)consider
         Account account = getAccount( AccountID accountID ) ;          // or
         Account account = findAccount( AccountName accountName ) ;
         ... AccountInfo = account.toString( FULL ) ;          // or
         ... AccountSummary = account.toString( SUMMARY ) ;     // or
         ... AccountBalance = account.balance() ;This abstracts the Account's identification, from an int, makes your code robust to change, and more flexible, and easier to understand.
    The business delegate pattern may have a methodThis is not good, the naming is particularly specific and relies on assumptions about the architecture, it looks like a a global function, yet should be a method of businesscomponent, which is also badly named.
    getAccountInfoFromBusiness(Accountnumber int)
              return businesscomponent.getAccountInfo(Accountnumber);
    }Instead consider the following. I've used abstraction to hide the implementation details, and the relations model real life, and I can handle my objects polymorphically.
         class Account { ... }
         class DayBook {
              Hashtable accounts ;
              public Account getAccount( AccountID accountID )
                   accounts.get( AccountID accountID )
         class MyApp
              DayBook salesDayBook = new DayBook() ;
              DayBook purchaseDayBook = new DayBook() ;
              Account account = salesDayBook.getAccount( theAccID ) ;
              Account account = purchaseDayBook.getAccount( theAccID ) ;
              }Here DayBook is a collection of Accounts, I've two instances, one for my sales one for my purchases.
    and the presentation tier components will have code
    containing invoking to getAccountInfoFromBusiness
    method.
    Now suppose if business component method signature
    changes then the signature of business delegate class
    will also change. This turn in requires changes to
    presentation tier components. I really dont understand
    why business delegate pattern is needed.The Business Delegate is not really a pattern as such, it is an appliction of the Proxy pattern abstracted into Business language/terminology.

  • Design Pattern Discussion

    I am now reading on a surogate pattern, I am not sure as to what is the difference between a Proxy pattern and a state pattern.
    I currently reading the Thinking in Patterns by Bruce Eckel I really have probelm in understanding the Surrogate pattern design. I need concrete examples, is there any other sites or articles I can refer to or perhaps read.
    Please give me some light and direction on this thank you

    What's the Surrogate pattern? is it another name for
    Proxy?Eckel uses the term "Surrogate" as a "category" containing Proxy and State.

  • About JCOM and JMS

              if i use JCOM to communicate Microsoft Client and JMS server,can i code the client
              just like in the java,get connectionFactory,create connection,create session,create
              sub,implement onMessage method,set Listener,then wait coming message
              just use class reference(idl) to instead the true class,is it right?
              

              jerry8006 wrote:
              > if i use JCOM to communicate Microsoft Client and JMS server,can i code the client
              > just like in the java,get connectionFactory,create connection,create session,create
              > sub,implement onMessage method,set Listener,then wait coming message
              >
              > just use class reference(idl) to instead the true class,is it right?
              I think so, but I'm not sure how JCOM would work async - try the jcom
              newsgroup. Note that coding it this way would mean that every call
              would end up being a remote call, including things like
              "textMessage.getText()". It would be simpler and better peforming to
              just to use WebLogic JMS C client or the ActiveJMS generic JMS wrapper.
              If you plan to use JCOM I would seriously consider using simple session
              beans as wrappers that make a the JMS calls on the server side (a
              "proxy" pattern). For example, the ejb proxy "send(destName, text)"
              call would create the jms connection-factory/connection/session/sender
              if they don't already exist, and then call sender.send().
              Tom, BEA
              

  • JCOM and JMS

    I tried using JCOM example given in weblogic documentation. In the example an excel sheet macro tries to connect to the weblogic server and looks up an object bound on the JNDI tree.
              but I am getting following error : "An error occured while binding EJB objects." Could anyone please throw some light on whats happening and how can I correct this error.
              Thanks in advance,
              Tarun

              jerry8006 wrote:
              > if i use JCOM to communicate Microsoft Client and JMS server,can i code the client
              > just like in the java,get connectionFactory,create connection,create session,create
              > sub,implement onMessage method,set Listener,then wait coming message
              >
              > just use class reference(idl) to instead the true class,is it right?
              I think so, but I'm not sure how JCOM would work async - try the jcom
              newsgroup. Note that coding it this way would mean that every call
              would end up being a remote call, including things like
              "textMessage.getText()". It would be simpler and better peforming to
              just to use WebLogic JMS C client or the ActiveJMS generic JMS wrapper.
              If you plan to use JCOM I would seriously consider using simple session
              beans as wrappers that make a the JMS calls on the server side (a
              "proxy" pattern). For example, the ejb proxy "send(destName, text)"
              call would create the jms connection-factory/connection/session/sender
              if they don't already exist, and then call sender.send().
              Tom, BEA
              

Maybe you are looking for

  • My fiance and i share 1 icloud account on 2 iphones, after the ios 7 update he can now see all my messages on his phone, how can i fix this?

    my fiance and i share 1 icloud account on 2 iphones, after the ios 7 update he can now see all my text messages that I type on his phone, how can i fix this?  I don't see any of his, just the other way around.  The icloud account is in my name.  also

  • BAPI_SHIPMENT_CREATE

    How can i create a shipment with the execution dates in the deadline?? How i fill the BAPISHIPMENTSTAGEDEADLINE? can anybody post an example please? i need to create a shipment with status "shipment completion". thanks

  • Find range partition key information

    Hello, I try to insert a row in a table and I get this msg: "inserted partition key is beyond highest legal partition key". This table has a range partitioning key but I don't know on which colmn(s) this partioning is working. Is there a way to find

  • Depploy error

    was building a web application. Everything has been fine all day, until now. When i clicked run, the deploying to tomcat peroid was taking too long so i stopped tomcat. Now when i try to run the porgram i get: C:\Users\evesham\WebApplication1\nbproje

  • Using AirPort Utility 5.3.1 or later to make a copy of the Time Capsule disk

    Can I use AirPort Utility 5.3.1 or later to make a copies of specific folders within the Time Capsule disk? http://support.apple.com/kb/HT1281 I see this link that explains how you can make an archive of TC files directly to an external USB (greatly