具有不同返回类型的设计模式 [英] Design pattern with different return type

查看:148
本文介绍了具有不同返回类型的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个具有某些功能的类,返回类型是A(只是假设)

我需要创建几个只使用数据A的类,进行一些自定义并以不同的格式返回它。 (比方说,classB返回Type B,C类返回Type C。

B类和C类都使用相同的数据A,但定制很少,添加的数据很少。



请指导我在这种情况下可以使用哪种设计模式。



问候,

Saurabh



我的尝试:



我分析了构建器,适配器和工厂模式。但是所有都返回void或相同的数据类型。我希望我的返回类型不同。

Hi,

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.

Regards,
Saurabh

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.

推荐答案

使用组件策略 / pattern(或其他):



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;}
   ...
}


这篇关于具有不同返回类型的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆