Tim,

> I actually think a Expando model might be more appropriate combined with
> adapters.

Hi. As far as I understand it, Expando models allow you to store
additional data, but I'm looking to change behaviour, not state.

> have a "pattern" you want to use, which doesn't really suit the environment
> in which your
> developing. Often patterns described suit the restrictions of specific
> languages like
> Java, and python has it's own approaches.

I realise that using the term "Pattern" with python developers can
evoke nightmares of being kidnapped by Java architects and forced to
develop Enterprise Java Beans whilst Larry Ellison tortures their
pets.

I'll try to  rephrase the problem without reference to any evil Gang
of Four literature.

You've got a class with 10 attributes and 10 methods. The behaviour of
all of these methods changes radically depending on the value of one
of the attributes (e.g. 'status', which has one of 3 possible values.
What's the best way to model this? Inheritance seems a very elegant
approach to me. See below for a facetious example. Once you expand
this to 30 significant methods the benefits of this approach are very
apparent.

class Developer():

    experience = StringField()

    def react_to_question(self):

        if self.experience == 'Novice':
            self.wtf?()
        if self.experience == 'Recent Graduate':
            self.patronise_questionner()
        if self.experience == 'Disillusioned':
            self.wonder_why_not_a_fireman()
            self.reach_for_bottle()
# Alternative

class BaseDeveloper():
    pass

class Novice(BaseDeveloper):
    def react_to_question(self):
        self.wtf?()

class Graduate(BaseDeveloper):
    def react_to_question(self):
        self.patronize_questionner()

class Disillusioned(BaseDeveloper):
    def react_to_question(self):
        self.wonder_why_not_a_fireman()
        self.reach_for_bottle()

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to