模板方法模式是共享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)

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.

This pattern could be a good solution if you just want to create several soap connect.

An other one could be to use interface. It will tell your program that every class that implements SoapItf (for example, rename it if you want) are able to perform soap method.

If you look for an evolutive application, maybe you'll need to connect with Rest webservice after so you can create an abstract class Werbservice, two class Soap and Rest that extends it and this two class implements interface SoapItf ans RestItf respectively.

This method helps using polymorphism, an important concept in OOP.

class diagram

In this case I can add method to Soap or Rest without changing both.

After that if you have specificity with Soap like in your example, you could extends Soap class. It will be easier to evolve the application and using package architecture (interesting if you work with namespaces)

In my opinion, you can use template pattern to manage a common resource that is spreadable in sub-classes. For instance, you have a soaplogin common abstract class and that might have some resource that can be used by most of the sub-classes. Then it's better to manage that resource in super-class and pass the callback in subclass to use the resource of the super-class. Advantage is that you are managing resource at a single place.

For example, I have a common resource in my super-class. I can create a callback passing resource as a parameter.

interface ResourceCallback {
     T call(Resource resource);
}

Then can define a abstract method in super-class like as doWithResource(ResourceCallback callback) and all the subclass can now use the resource with their own implementation of their methods.