Skip to content Skip to sidebar Skip to footer

Proper Way To Instantiate Subclasses?

So I'm doing a small Pygame programm and I'm trying to structure the stuff in decent look, this is where I stucked. class Screen(object): def __init__(self, width, height):

Solution 1:

You don't want GameMenager to be a sub-class, here. Rather, you want to pass a screen instance to the GameMenager instance:

classGameMenager(object):def__init__(self, screen):
        self.screen = screen
        self.screen.SURFACE #can do w/e you want with it#for example:defprint_surface(self):
        print self.screen.SURFACE

And instantiate it as follows:

>>>s = Screen(640, 480) >>>gm = GameMenager(s)>>>gm.print_surface()
10

Post a Comment for "Proper Way To Instantiate Subclasses?"