Dofactory.com
Dofactory.com
 Back to list
Views:   5.6K
Replies:  1
Archived

Help to decide appropriate pattern to be implement.


What is the best solution to resolve the following problem?

Problem: I would like to implement generic business logic (method) which can be invoked by any methods irrespective input type.
Scenario:
        For example: 
                Generic method:
                                public <complexType> GenericMethod(<ComplexType>)
                                {
                                                ... business logic implementation
                                                ... return <complexType>
                                }
                Client Method 1:
                                public <complexType> Client1(<complexType1>)
                                {
                                                ... call GenericMethod<complexType1>)
                                }
                Client Method 2:
                                public <complexType> Client1(<complexType2>)
                                {
                                                ... call GenericMethod<complexType2>)
                                }

Question: If you have noticed, In above scenario "Client Method1" and "ClientMethod2" is passing different input type and method is expecting same return type.

Is there any pattern or mechanism which will decide type and based on that it will invoke appropriate method.
Nirav Valera, Aug 29, 2011
Reply 1
Hi Nirav

I would suggest Strategy pattern where you can use different strategy methods based on the context.

Thanks & Regards
Pubudu Thilakarathna
Pubudu Thilakarathna, Aug 30, 2011
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.