Hi Malcolm
  Many thanks for your verbose answer, i have to think the way i will
represent this. By the moment i don't have instance variables over the
state objects, so i was thinking that i could store the state "name"
and make a getter using something like a Factory. How much awful seem
to you this?

Many Many, Thanks
Sebastian

On 28 oct, 06:23, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Sun, 2007-10-28 at 20:18 +1100, Malcolm Tredinnick wrote:
> > On Sun, 2007-10-28 at 08:43 +0000, [EMAIL PROTECTED] wrote:
> > > Hi Malcolm
> > >   In my design i have a class called publication, that behaves
> > > different depending on the "state", so i have an state hierarchy that
> > > implement via polymorphism the different ways the publication behaves.
> > >   I have been reading the djangobook and searching the net, looking a
> > > way to implement this without lucky. Maybe i'm asking something a lot
> > > trivial, sorry me if that is the case.
>
> > You can simulate inheritance by using foreign keys or one to one keys.
> > For example:
>
> >         class Parent(models.Model):
> >             some_data = ...
> >             ....
>
> >         class Child(models.Model):
> >             parent = models.ForeignKey(parent, unique=True)
> >             ...
>
> I forgot to mention the alternative: storing complex object-oriented
> hierarchies in SQL databases is officially a Hard Problem. It's just not
> a natural fit for all cases. So turn your problem around a bit and don't
> get stuck on one particular modelling method. Instead of storing the
> classes directly like this, try to think of a way to flatten your
> collection of classes. For example, if all of you "state nodes" can be
> stored in a single model somehow, then you only need to store, in
> addition to these models, the state transitions.
>
> Remember, state machines existed long before object-oriented
> programming. There are other ways to represent the same information
> without needing polymorphism and this might lead you to a more natural
> representation.
>
> Regards,
> Malcolm
>
> --
> The cost of feathers has risen; even down is 
> up!http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to