> Source files are source files, classes are classes.
"P.Hill" wrote...
>> Source files are source files, classes are classes.
>
[quoted text clipped - 3 lines]
> dictates the physical -- the files on disk. I found it to be a
> very useful assumption which avoids all kinds of headaches.
Not entirely. It's correct in that the design for a specific class generates
only one .class-file.
But you still have the possibility to have more than one class definition in
a single source file.
So they who designed Java only seem to have "partial problems" with the
mapping... ;-)
> Yet, I could a place for a language support for partial classes
> per file as per your comment:
[quoted text clipped - 3 lines]
>
> But then I haven't run into a class that I really wanted to break up.
Although I never have *needed* it, I've come across situations where I
actually *wanted* to...
> Here is a question. What is the advantage of separate files for
> partial classes, other than to avoid any perceived disadvantage to
> large source files?
Just to give an example:
A couple of years ago, I developed a GUI-builder for Java, to easily
generate "standard" GUI:s, which later on could be "enhanced" by manually
inserting code into the generated code. If the possibility to split the
definition into several files had existed then, I wouldn't have needed to
parse an already generated file, in order to keep the manually inserted code
when regenerating a changed GUI.
// Bjorn A
Oliver Wong - 15 Feb 2006 15:18 GMT
> A couple of years ago, I developed a GUI-builder for Java, to easily
> generate "standard" GUI:s, which later on could be "enhanced" by manually
> inserting code into the generated code. If the possibility to split the
> definition into several files had existed then, I wouldn't have needed to
> parse an already generated file, in order to keep the manually inserted
> code when regenerating a changed GUI.
My solution was to not let the user edit generated files. Instead, the
code generator generates an interface that the user has to implement, in a
class with a specific name. E.g.
<example>
public class GeneratedCode {
public IHumanWrittenCode hwc = new HumanWrittenCode();
public void doA() {
doStuff();
hwc.helpMeWithA();
doMoreStuff();
}
}
public interface IHumanWrittenCode {
public void helpMeWithA();
}
</example>
There'd be a compile error "class not found" on the "new HumanWrittenCode()"
expression. Using Eclipse, the user just needed to right click and choose
"Create class", and the class with the implementing the correct interface,
with the correct filename, in the correct package, would be created, which
the user could then fill out.
- Oliver
Hendrik Maryns - 15 Feb 2006 15:22 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
Oliver Wong schreef:
>> A couple of years ago, I developed a GUI-builder for Java, to easily
>> generate "standard" GUI:s, which later on could be "enhanced" by
[quoted text clipped - 28 lines]
> implementing the correct interface, with the correct filename, in the
> correct package, would be created, which the user could then fill out.
Interesting application of the template method pattern.
H.

Signature
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
P.Hill - 16 Feb 2006 03:08 GMT
> Just to give an example:
>
> I wouldn't have needed to
> parse an already generated file, in order to keep the manually inserted code
> when regenerating a changed GUI.
I find subclassing to be a very useful solution in this case,
for example, I have used it to extend hibernate generated classes.
-Paul
Oliver Wong - 16 Feb 2006 15:01 GMT
>> Just to give an example:
>>
[quoted text clipped - 3 lines]
> I find subclassing to be a very useful solution in this case,
> for example, I have used it to extend hibernate generated classes.
If the generated code is the one driving the application, it needs to
know the name of your subclass to create an instance of it. Which means (in
this case) you would need to provide parameters giving the name of the
subclass to the code generator. At which case, you might as well just
provide parameters to have it generate the code that couldn't be generated
in the first place.
- Oliver
P.Hill - 17 Feb 2006 06:41 GMT
>> I find subclassing to be a very useful solution in this case,
>> for example, I have used it to extend hibernate generated classes.
>
> If the generated code is the one driving the application, it needs to
> know the name of your subclass to create an instance of it.
The way I was using such a relationship, the class is generated, it is
just the bare bones generated by the tool for O/R mapping (sublcassed
from object but with all the right properties. _I_ subclass and
implement any appropriate additional interfaces special for my use.
Customization goes on top the auto generated class, not the other way
around.
YMMV
-Paul
Finomosec - 16 Feb 2006 21:19 GMT
P.Hill schrieb:
>> Just to give an example:
>>
[quoted text clipped - 5 lines]
>
> -Paul
Extending generated classes is a good aproach.
Especially with hibernate i prefer the opposit direction:
Writing pojos (plain old java objects) and generating the
database-mappings (per xDoclet or [in the newer version] annotations).
With interfaces or extensions most problems can be solved.
Anyways there are three additional possibilities:
1.) reflection/proxy
http://www.dpunkt.de/java/Die_Sprache_Java/Objektorientierte_Programmierung_mit_
Java/75.html
2.) bytecode-generation
http://cglib.sourceforge.net/
3.) outsourcing
Source the relevant information out to a config-file and write your
application accordingly general/generic ... (XML is most useful)
Greetings Finomosec;
P.Hill - 17 Feb 2006 06:45 GMT
> Extending generated classes is a good aproach.
> Especially with hibernate i prefer the opposit direction:
> Writing pojos (plain old java objects) and generating the
> database-mappings (per xDoclet or [in the newer version] annotations).
That works too, then I'd just have to use annotation marking just the
appropriate code, but not being afraid of SQL, I still find I start
with a table create (or a pre-existing DB structure) and then use tools
to generate code to support me in the app.
But I hear ya on using POJOs. That is the way to go.
-Paul