> > Hi.
> >
[quoted text clipped - 31 lines]
>
> - Oliver
> Oliver Wong ha scritto:
>
>>> Hi.
> 1.
> If I fix the name e. g. to myProcessing, how I can buid the class
> (without errors) since it have a reference to myProcessing method and
> myProcessing is not yet available?
The processing code interface you define will provide this name for you.
i.e.
public interface MyProcessorInterface
{
public void myProcessing(String record);
}
The you can create concrete classes that implement this interface
i.e.
public class ImplementIt1 implements MyProcessorInterface
{
public void myProcessing(String record);
{
// do my specific logic here
}
}
public class ImplementIt2 implements MyProcessorInterface
{
public void myProcessing(String record);
{
// do my different logic here
}
}
Finally you pass an instance of a class that implements the interface to your
fileInp class.
i.e.
public class fileInp
{
MyProcessorInterface processor = null;
public fileInp(MyProcessorInterface processor)
{
this.processor = processor;
}
public void Execute()
{
while(!eof())
{
String record = readRecord();
processor.myProcessing(record);
}
}
}
> 2.
> Could be a good idea reference instead a dummy method inside fileInp
> (wich do nothing) and in some way change it's reference dinamically to
> point to the method of my processing class?
> So, some other comment could be appreciated. Thanks again. Franco.
Dražen Gemić - 20 May 2006 16:07 GMT
If it needs to be an Event, you can look at java.util.EventObject
and java.util.EventListener. Keep in mind that the class that posts
an event will not wait for event handler to return. Not by itself.
DG
Andy Flowers - 20 May 2006 20:52 GMT
> If it needs to be an Event, you can look at java.util.EventObject
> and java.util.EventListener. Keep in mind that the class that posts
> an event will not wait for event handler to return. Not by itself.
>
> DG
or Observer & Observable.
If I understand the OP he has used Delphi and this has an easy way to replace
method addresses at run time, it basically uses pointers behind the scenes. This
is one of the techniques that made it into C# (same language designer) using, if
I recall, delegate & event.
ffellico@inwind.it - 21 May 2006 08:12 GMT
Andy Flowers ha scritto:
> > Oliver Wong ha scritto:
> >
[quoted text clipped - 64 lines]
>
> > So, some other comment could be appreciated. Thanks again. Franco.
Thank you Andy.
I have worked a lot with my problem and now I solved it using
reflection as Oliver suggest me. I learned a lot of things working
around this problem!.
Now I will work with interfaces as you suggest and I will refine my
solution, but mainly all this work will be a useful job to improve my
know-how in this powerful language.
So many thanks to all of you. Franco