Re: [pygame] Initializing and Reinitializing Instance variables

2019-05-27 Thread Greg Ewing

Irv Kalb wrote:

I hadn't thought of the extra "Session" object, it sounds like an interesting
approach.  However, I'm looking for a clear solution that I can teach to
students who are just learning about OOP.


Don't think of it as an extra session object, rather think
of it as creating a new Game object for each game. I think
that's actually a clearer and more OO way to approach the
problem than trying to clear out and re-use an existing
object.

--
Greg



Re: [pygame] Initializing and Reinitializing Instance variables

2019-05-27 Thread Greg Ewing

mspaintmaes...@gmail.com wrote:

class ApplicationContext:
  def __init__(self):
self.session = GameSession()

  def reset(self):
self.session = GameSession()

Nope, this doesn't solve your fundamental problem of getting rid of a 
duplicate assignment,


I'd probably do it like this:

  class ApplicationContext:

def __init__(self):
  self.session = None
  reset()

def reset(self):
  self.session = GameSession()

--
Greg