Derived data and process, a pattern?

F

f

The problem is this:

I have different data type, say data1, data2, each one has a special
way for I/O.

class Data1{...}
interface IO1 {
Data1 load();
void save(Data1 data);
}

class Data2{...}
interface IO2{
Data2 load();
void save(Data2 data);
}

However, I want to orgnize them in a uniform way, So I set up a frame
work, say:

class Data{...}
interface IO{
Data load();
void save(Data data);
}

I derive data1, data2, ... from Data.
I derive IO1, IO2 from IO.

But I want IO1 works only on data1, IO2 works only on Data2...

Thus,

class Data1 extends Data{...}
interface IO1 extends IO {
Data1 load();
void save(Data1 data);
}

class Data2 extends Data{...}
interface IO2 extends IO {
Data2 load();
void save(Data2 data);
}

I want in the derived interface "load" and "save" replace the same
method in IO, but with different data type. But looks like this does
not compile. How can I fix it?

Should this be a pattern? Each Process works on a Special data, but
global, they still follow some interface so they can be treated the
same way if nessary.

Thanks,

ff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top