Python OOP question

K

k3xji

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.

Is there any paradigms. patterns specifically in Python for above like
situations, where in a library, we design some objects to be abstract
as possbile and other non-inheritable objects using the functions?

Or just any feedback on this Design structure?
 
G

Gabriel Genellina

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...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top