Board index » delphi » Re: Code generation - Class hierarchy

Re: Code generation - Class hierarchy


2005-02-25 08:33:10 PM
delphi120
"Andrea Raimondi" <XXXX@XXXXX.COM>a écrit dans le message de news:
XXXX@XXXXX.COM...
Quote
As it is evident, I am trying to do an ASP code generator(don't worry, no
C.A.S.E. approach, just a way to manage the bulk work automatically).
I would advise you to look at implementing the Visitor pattern in your
hierarchy. Performing operations on any tree structure is so much easier.
Joanna
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 
 

Re: Code generation - Class hierarchy

Quote
As it is evident, I am trying to do an ASP code generator
<snip>
Am I following the right direction?
Two possible methods spring to mind immediately (I'm sure there are
others). One is the CodeDOM approach you seem to be using. Your classes
are missing something, and that is the links between objects - eg
functions have parameters and return types, local variables, code blocks
etc. If you have some way of linking them together into a tree (a tree
is normal for code representations like this) then as Joanna says,
Visitor is a natural way to navigate that tree. However, I'd only do
that if you need to have more than one thing happen on a tree traversal,
or that thing is complex. If you are only generating code, it is
debatable whether Visitor is needed (there was a discussion about this
in a thread here not long ago).
The other, possibly simpler, approach is to use code templates with
place holders. On my first OPF, I never got around to a generic mapper
class (mapping BOs to database tables). Instead a wrote a little wizard
in about half an hour that just had special tags in a template (text)
file that got replaced with class names etc. to generate a mapper class.
If you are just generating boilerplate code, this is an easier approach.
I (ab)used TPageProducer to do it, BTW, and the technique was in that
paper I uploaded to binaries a while back. Email me if you'd like to see it.
Cheers,
Jim Cooper
__________________________________________
Jim Cooper XXXX@XXXXX.COM
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
__________________________________________
 

Re: Code generation - Class hierarchy

Quote
Thus, it is not really a "boilerplate" code
Code templates can be reasonably sophisticated, but if you are allowing
all sorts of new things to be defined, and in addition you want them
displayed in more than one way (code and diagram) then the CodeDOM
approach + 2 Visitors sounds like a better way to tackle it.
Cheers,
Jim Cooper
__________________________________________
Jim Cooper XXXX@XXXXX.COM
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
__________________________________________