Questions about app design - OOP with python classes

2007-03-01 Thread adriancico
Hi

I am working on a python app, an outliner(a window with a TreeCtrl
on the
left to select a document, and a RichTextBox at the right to edit the
current
doc).

I am familiarized with OOP concepts and terms but I lack practical
experience
, so any comment/tip/pointer to docs will be welcome.

So far, I have created a separated class for each important
element of my app
- the main Frame (cFrmMain)
- the TreeCtrl
- the TextCtrl at the right
- a cDocument class that contains the entire file with all
docs
  and manages creation/deletion/saving to disk, etc
- classes for the toolbar, the menubar, etc

With this design, pretty much everything is encapsulated in it
respective
class. However, that means that the main program logic is in the Frame
class.
>From there, it instantiates the other classes and is responsable of
the
communication between them.

For example, the user deletes a node on the Tree, this raises an
event
on cFrmMain (the main Frame class). In the event handler, cFrmMain
notifies
cDocument that a node (and the associated text) has been deleted so
the master
file is modified accordingly.

The problem is, I have been implementing some funcionalities to
test this
design, I have less than a dozen operations implemented and cFrmMain
has grown
more than acceptable, starting to get confusing.

This design feels "not quite right" to me, I've been considering
allowing
the different classes to know of the existence of each other and pass
messages
between them. I would lose encapsulation (I think), and I don't know
if that would be
(very) bad... and I'm not sure if with this design I will gain or lose
clarity on the code.

My questions ( at last :-) ) are:

¿Should I stick to my first design idea, eventually moving code
from the
main Frame to modules to gain clarity?

¿Is the second idea I present "correct" (I know it'll work, what I
want to
know is the clearest way of organize my code)?

¿Am I doing this wrong from the start and have to use another
design?

Thanks for reading this long post. Any comment, hint or pointer to
docs will
be greatly appreciated.

Regards
Adrián Garrido

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about app design - OOP with python classes

2007-03-01 Thread adriancico
On Mar 1, 9:45 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

> As a side note : hungarian notation is usually considered bad form here.
> Look here for usual naming 
> conventions:http://www.python.org/dev/peps/pep-0008/

Thanks for the tip. It's been too many years of VB6, and its difficult
to leave old habits
behind :-)

>
> > With this design, pretty much everything is encapsulated in it
> > respective
> > class. However, that means that the main program logic is in the Frame
> > class.
>
> What do you call "main program logic" exactly ?

What I mean is that in the frame code is where all decisions are
taken. The frame handles the
other controls events, decides what needs to be done, calls the
necesary methods of the other controls, etc. The other widgets just
"do the work" when called from the Frame. But this is not
necesarily bad, as you point out below.

> Using the main frame as a mediator between the different widgets is a
> well-known design pattern, named - suprisingly - mediator. The
> motivation is that it avoid each and every widget to know about the
> existence of every other widget. You may want to read about this pattern
> - but note that most litterature about design patterns is expressed in
> terms of statically typed languages (Java, C++ etc), and that dynamic
> languages like Python usually don't need that much boilerplate and
> complication (IOW : try to understand the pattern itself, not to blindly
> apply it).
>
> What's your looking for IMHO is the "controller" part - the one that
> glue together the "view" (main frame and all it's widgets) and the
> "model" (mostly, your document). Here again, googling for
> "model/view/controller" (MVC) may be a good idea.
>

I understand (I've been in wikipedia :-) ). Right now the Frame is the
controller as well
as the view. Moving out the "controller" code to another module seems
to me the
path to follow. I'll start to look out for MVC related material.

My problem was that, altough I knew OOP basics, I didn't know how to
apply them exactly. Thanks
for your answer, it has cleared many things.

> Note that there's nothing Python-specific in your question. But since
> comp.object is one of the worst places on earth to ask questions about OO...

I am developing in Python, so it made sense to me to post here. But
you are right, the question
is off-topic. Sorry for that.

Thanks again and regards
Adrián Garrido

-- 
http://mail.python.org/mailman/listinfo/python-list