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