[Tutor] What Design Pattern for Document class (NOT URGENT)

Karim karim.liateni at free.fr
Thu Aug 26 08:43:29 CEST 2010


Hello All,

I want to  build some classes by optimizing their design.
But I want to keep quite 'simples'. I have a XML  document
which represents let's say some rules (id, description, value).

My first idea is to create an *docrules* class which holds my document.
This class will use 2 other instances from 2 respectives classes
reader and writer. The main method of  reader is get().
The main method of writer is write(). To resume I have:
                   
------------------------------                                  
-----------------------
                   -     docrules         
-----------------------------------      reader     -
                   
------------------------------                                  
-----------------------
                   -       filename       
-                                  -       file         -
                   - 
----------------------------                                  
-----------------------
                   -                            
-                                  -       get()       -
                   -                            
-------                            -----------------------
                   ------------------------------     -
                                                      -
                                                      
-                             ------------------------
                                                      
-------------------------------    writer        -
                                                                                    ------------------------
                                                                                    -      file           -
                                                                                    ------------------------
                                                                                    -      write()     -
                                                                                    ------------------------

The *docrules* will do the parsing (*xml.etree* very effective)
and create the reader and the writer instance.
I want to create 2 others classes (or more) more specific which have
more the knowledge about the XML documents structures.
*SpecificRuleReader*, *SpecificRuleWriter* which are deriving resp.
from Reader and Writer which hold resp. *getSpecificRules*() (use of 
get('/tag1/tag2/tag3/specificTagRules') and a* writeSpecificRules*():

-----------------------------                      
---------------------------------
       reader                                             writer
-----------------------------                      
---------------------------------
             ^                                                   ^
              |                                                    |
-------------------------------                    
-----------------------------------
*SpecificRuleReader* *SpecificRulesWriter*
-------------------------------                    
-----------------------------------
*getSpecificRules*() *writeSpecificRules()*
--------------------------------                   
--------------------------------------

My purpose is to separate as far as possible XML representation from
core classes. I will have certainly more SpecificrulesReader/Writer
classes becauses the document is huge and several discipline rules
will be adressed. I don't want necessarily have 2 big classes which
know everything about XML document because I will have too many
methods.

So, for if anybody has this kind of experience or any design pattern idea,
I will be enchanté.

Regards
Karim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100826/a8628f4e/attachment.html>


More information about the Tutor mailing list