Specialized Server provides four interfaces to connect – HTTP, HTTPS, Telnet and SSH. We have a specific priority to connect with the server. e.g. Following sequence to be followed to connect to the server – HTTPS, HTTP, Telnet and SSH. It means that first the client will try to connect with HTTPS. If it fails then it will retry it again with HTTPS. If this fails again then it will try with HTTP and so on. I will get the respective connection object one’s it will success. e.g. if connection with HTTP get success then it will return an HTTP connection object.
Can you please help me to findout any pattern which can be helpful here?
Currently I am thinking to implement it using proxy. I will have a ConnectionProxy Class and this class will find the first successful connection protocol.
I’m not sure the difference between a
ConnectionProxyand aConnectionobject. The Connection objects should have a standard interface to allow them to be used interchangeably and implementations which specify their differences.“Interfaces” in Perl are lightweight. They’re just a formulation of expectations that an object would have to fulfill in order to say that the object
DOESthat role.As for a simplest implementation of a Connection factory
Now, I would tend to keep the list of connection classes in some configuration somewhere (preferably YAML, for me). But again, this is the simplest implementation of a fail-over.
Just mainly as a development issue, I find it is useful to have generic tests for each interface. If you say Class C
DOESInterface I, the generic test can verify this fact before you add it to the list of available interface implementations. The test can verify the same things that a compiler can–and more.