在java中设计模式的建议 [英] suggestion on design pattern in java

查看:100
本文介绍了在java中设计模式的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有用的建议,在java中的以下问题的设计模式,
我有三个类,如,

  class A extends X implements Y {
doA()
}
class B extends X implements Y {
doB()
}
class C extends X实现Y {
doC()
}

现在我想创建一个类D应该分别重用方法doA,doB一个类A,B和C的doC。



任何人都可以为上述问题提出一个设计?

提前感谢
Lakshmipathi。

解决方案

我想你需要使用范例喜欢组合继承。包含 A B 的实例的设计类 D C 并根据需要调用他们的方法。另外,如果需要, D 可以实现 Y ,并将相应的API调用委托给 A B C


I need some useful suggestion on design pattern for following problem in java, I have three classes like,

class A extends X implement Y{
  doA()
}
class B extends X implement Y{
  doB()
}
class C extends X implement Y{
   doC()
}

Now I would like create a class D that should reuse methods doA, doB an doC of classes A, B and C respectively.

Can anyone suggest me one design for the above problem?

Thanks in advance, Lakshmipathi.

解决方案

I think you need to use paradigm "Prefer composition over inheritance". Design class D that includes instances of A, B, C and call their methods as necessary. In addition, D can implement Y if necessary and delegate corresponding API calls to either A or B or C.

这篇关于在java中设计模式的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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