SV: [Tutor] Stuck with classes

Danny Kohn danny.kohn@systematik.se
Thu, 4 Oct 2001 22:09:03 +0200


Find oop somewhat complicated I must say. Obviously I can go back to =
functions but I at least I want to understand it proper so that my =
choice will not be one of ignorance.

Danny Yoo is correct in that I want to be able to have many concurrent =
instances of a matrixPanel.

Thanks for all the comments. Will study them carefully.
/Danny Kohn

| -----Ursprungligt meddelande-----
| Fran: tutor-admin@python.org [mailto:tutor-admin@python.org]For Danny
| Yoo
| Skickat: den 4 oktober 2001 21:36
| Till: Lloyd Kvam
| Kopia: Danny Kohn; Python Tutor mailing list
| Amne: Re: [Tutor] Stuck with classes
|=20
|=20
| On Thu, 4 Oct 2001, Lloyd Kvam wrote:
|=20
| > I don't follow what you are doing but....
| > gg.addGen(p)
| > AND within the addGen method
| > yyy.AddWindow(p.GridSizer, ...)
|=20
| This approach will work.  However, it hardcodes genGrid.addGen to =
always
| use that particular matrixPanel, and that might limit the usefulness =
of
| the genGrid class.  It might be ok if this is a one-shot thing, but =
it's
| usually better to make classes stand alone without depending on global
| variables.
|=20
| If we have two genGrids, for example, these two might not necessarily =
want
| to share the same matrixPanel... maybe they're jealous!  *grin*
|=20
|=20
| To avoid potential catfights, we can use a similar solution: we can =
pass
| off a matrixPanel to the genGrid as soon as the genGrid is created:
|=20
| ###
| class genGrid:
|     def __init__(self, matrixPanel):
|         self.matrixPanel =3D matrixPanel
|=20
|     def addGen(self, panel):
|             # Create Function table
|             self.DescWin =3D wxGrid(...)
|             [...]
|             yyy.AddWindow(self.matrixPanel.GridSizer)
|=20
| p =3D matrixPanel(frame1, -1)
| gr =3D p.makeGrid()
| gg =3D genGrid(p)
| ###
|=20
| Here, we can say that every genGrid remembers which matrixPanel it is
| associated with.  That is, a genGrid always "has a" matrixPanel, since
| it's now part of the constructor: every genGrid that springs into
| existence will have a matrixPanel in it.
|=20
|=20
| And also a good reason to involve it in the constructor: if a genGrid
| can't function --- can't live --- without its matrixPanel, then that's =
a
| sign that we should get genGrid involved, hand in hand, with a =
matrixPanel
| from the very beginning.
|=20
|=20
| Hope this helps!
|=20
|=20
| _______________________________________________
| Tutor maillist  -  Tutor@python.org
| http://mail.python.org/mailman/listinfo/tutor
|=20