T
Timo Nentwig
Hi!
This is the problem: An object gets data passed in the constructor and
needs to handle it but does not know what kind of data it is passed to.
So it additionally needs an Adapter that implements a common interface
which does wrap that data. I thought about something like this:
public DataProcessor
{
// needs to be implemented
protected astract class Adapter
{
// I'd prefer it if would be static
protected abstract Object get(int index);
}
protected Object data;
public DataProcessor(Object data)
{
this.data = data;
}
public void process()
{
for (int i = 0; ...)
blah((new Adapter()).get(i));
}
}
Which would be instantiated like this:
DataProcessor dp = new DataProcessor(data)
{
protected class DataProcessor.Adapter
{
protected Object get(int index)
{
wrap(DataProcessor.this.data);
}
}
});
But I don't quite get it working - and I can instantiate DataPRocessor
without implementing the Adapter...somebody to give me some coaching on
Inner Classes? Other solutions to the problem are welcomed as well...(
as long as it is not DataProcessor.setAdapter()
TIA
Timo
This is the problem: An object gets data passed in the constructor and
needs to handle it but does not know what kind of data it is passed to.
So it additionally needs an Adapter that implements a common interface
which does wrap that data. I thought about something like this:
public DataProcessor
{
// needs to be implemented
protected astract class Adapter
{
// I'd prefer it if would be static
protected abstract Object get(int index);
}
protected Object data;
public DataProcessor(Object data)
{
this.data = data;
}
public void process()
{
for (int i = 0; ...)
blah((new Adapter()).get(i));
}
}
Which would be instantiated like this:
DataProcessor dp = new DataProcessor(data)
{
protected class DataProcessor.Adapter
{
protected Object get(int index)
{
wrap(DataProcessor.this.data);
}
}
});
But I don't quite get it working - and I can instantiate DataPRocessor
without implementing the Adapter...somebody to give me some coaching on
Inner Classes? Other solutions to the problem are welcomed as well...(
as long as it is not DataProcessor.setAdapter()
TIA
Timo