Python OOP question
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Sep 29 09:35:15 EDT 2008
En Thu, 25 Sep 2008 11:45:21 -0300, k3xji <sumerc at gmail.com> escribió:
> Hi all,
>
> I am trying to develop a game-server in python. Design is as
> following:
>
> - ConnectionManager - handling/distributing incoming connections
> - IOManager - handling IO recv/send operations on sockets.
> (inheritable)
> - Socket - basic async socket object
> - SocketServer - handling multiple socket object requests.
> (inheritable)
> - Options - holds the server options (inheritable)
>
> I want this code to be extensible as it can be. So I have developed it
> like this. I f one is going to implement some new feature, all needs
> to be done is to inherit IOManager or Server object to do it.
> Inheritable objects are IOManager, SocketServer and Options.
>
> But there is some feeling about this design that it can be better.
> Here is the main.py which I am using to execute the server:
>
> from Base.SocketServer import SocketServer
> from testIOManager import testIOManager
> from Base.Options import Options
> from Base.ConnectionManager import ConnectionManager
>
> iomgr = testIOManager()
> opts = Options()
>
> # calculate how many server objects to create
> # according to the maximum allowed client count.
> serverCnt = opts.MAX_CLIENT_COUNT / opts.MAX_CLIENT_COUNT_PER_SERVER
> Servers = []
> for i in range(serverCnt):
> server = Server(i)
> Servers.append(server)
>
>
> cmgr = ConnectionManager(Servers, iomgr, opts)
> cmgr.start()
>
> With current design as server object is inheritable, I need to pass it
> to ConnectionManager object. I just have a feeling that above design
> is bad in the sense of readability.
You may imitate how asyncore [1] handles channels: make the library
contain a (global) list of servers; the Server (base) constructor adds
itself to the list; and ConnectionManager uses that list if not
explicitely supplied one.
But I'm not sure it improves readability: there is no explicit link
between the Servers you construct and the ConnectionManager, but the
latter "magically" knows about all the formers. It's easier to manage,
though.
(I don't undersantd exactly why you insist in the inheritable part; isn't
the same if it were not inheritable? Maybe I don't get your main concerns
correctly...)
--
Gabriel Genellina
More information about the Python-list
mailing list