Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a class which have certain functionality and return type is "A" (just an assumption)
I need to create few class which will just use the data "A", making some customization and return it in different format. (Say, classB return "Type B" and class C return "Type C".
Both the Type B and Type C is using same data "A" but with few customization and few added data.

Please guide me which design pattern i can use in this case.


What I have tried:

I analyzed builder, adapter and factory pattern. But all are returning either void or same data type. I want my return type to be different.
Updated 17-Jul-18 8:52am
dan!sh 17-Jul-18 2:48am    
Are these classes simple DTOs or have some more functionality to them? Perhaps some code which you have tried will help.
CHill60 17-Jul-18 4:13am    
The Builder or Adapter design patterns are the appropriate ones. If you are getting the wrong return types then it must be the way you have coded them. Use the "Improve question" link on your post to show us your code.
By the way - a class does not have a "return type" - a method of the class may have a return type but not the class itself.
Richard MacCutchan 17-Jul-18 8:22am    
I think you have a misunderstanding about classes. It also sounds like all you really need is a base class, A, and child classes, B and C, which inherit A.
saurabh.15in 18-Jul-18 1:36am    
Sorry, I forgot to mention that there will be a method inside the class. Below is bit more explanation.

Web API- Class A- Method M->return type (custom class B)

Client - X- Consuming method M of Web API (This is wprking fine).

Now I have few more client.

Client - Y- (need same data which is being returned by Web API- Class A- method B but in different format)

In the same way, we have some more client who need same data but in different format.)

1 solution

Use the "component strategy / pattern" (or whatever):

Public Class A { ... }

Public Class B {
   public A ClassA {get;set;}

Public Class C {
   public A ClassA {get;set;}
Share this answer
saurabh.15in 18-Jul-18 1:38am    
Thanks Gerry, I am studying the component strategy pattern and will try to implement.
[no name] 18-Jul-18 14:21pm    
Great. Many (newer) "systems" are (or can be) built exclusively using prebuilt components that can be configured (game engines; machine learning pipelines; SAP process engineering).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900