&nbsp;&nbsp;&nbsp; i think Factory is not to the point,just concerned with its concept,factory <br>should only take care of producing proper protocol instance.i can't see any clue <br>of protocol context in the defintion of factory.so the boudary of factory is loom,i don't
<br>like it.or on other hand,we can it can be categoried into abstract factroy,then i proprose<br>following refraction.<br><br>class ProtoAbsFactory:<br>&nbsp;&nbsp;&nbsp; implements(interfaces.IProtocolFactory)<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; protocol=None
<br>&nbsp;&nbsp;&nbsp; context=None<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; numProtos=0<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; def buildProtocol(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp;&nbsp; def buildContext(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp; &nbsp;<br>class ProtoContext:<br>&nbsp;&nbsp;&nbsp; def doStart(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass
<br>&nbsp;&nbsp;&nbsp; def doStop(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp; &nbsp;<br>class ClientProtoContext(ProtoContext):<br>&nbsp;&nbsp;&nbsp; def startedCnnecting(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp;&nbsp; def clientConnectionFailed(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp;&nbsp; def clientConnectionLost(self):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br><br>class ReconnectingClientProtoContext(ClientProtoContext):<br>&nbsp;&nbsp;&nbsp; def clientConnectoionFailed(self,connector,reason):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connector=connector<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.retry()<br>&nbsp;&nbsp;&nbsp; def clientConnectionLost(self,connector,reason):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connector=connector<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.retry()<br>&nbsp;&nbsp;&nbsp; def retry(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connector.connect()<br><br>&nbsp;&nbsp;&nbsp;&nbsp; by introducing context,we make solution for some situation <br>very simple,just like http,since it is a stateless ,we have to bring
<br>in session to store state information during the communication,here by<br>refining the context ,we can easily achieve it