drphfy1198 2013-07-17 10:30
浏览 43
已采纳

模板方法模式是共享Soap方法的最佳解决方案吗?

I have a number of Soap Server classes most of which will need to implement 3 methods:

ping() // something to bounce a signal off to prove it has been reached
getCredentials($creds) // credentials to check sets session value
getCaller() // for logging, uses session value

As they form part of the WSDL defn they need to be public.

I am fairly sure this (I have christened it a Soaplogin) would need to be an abstract class (because it must never be instantiated on its own)

The concrete classes which extend then this core then have their own methods, none of which are shared.

I am searching for the best type of Pattern to use and am getting a bit confused, though I think a Template Method just about fits the bill - but I could just plain extend the SoapLogin class.

What advice can you give me on the best pattern to use, and maybe a preferred name for this class.

(while this uses ZF1 components it does not use full blown MVC - in case that was of importance)

  • 写回答

3条回答 默认 最新

  • dongrong1856 2013-07-17 11:43
    关注

    Prefer composition over inheritance.

    What you really do is you create completely independent interfaces that only by chance happen to have the same methods.

    Fine. Generic methods that always do the same - that should be in a class of it's own. But not ONE class for all these methods! One class per method!

    You can then add all these method classes to your server classes, and also add all the special functions the same way.

    That way you can combine any of the generic functions in any way, and add another only to one API if needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路