I defined an interface IPersistent
that has two methods load
and save
. Using these methods I can load or save the implementing class using whatever method they want.
public interface IPersistent {
void save();
void load(int id);
}
What I want now, is to implement a deleteAll
method, but it would have to be a static method, as it acts on class level, rather than object level. I tried using a static method in the interface, but that is not possible, as I would need to implement it in the interface, instead of any implementing class.
Typical usage would be something like this:
class Foo implements IPersistent {
void load(int id) { ... }
void save() { ... }
static void deleteAll() { ... }
}
List<foo> fooList = ...;
Foo.deleteAll();
for (Foo f: fooList) {
f.save();
}
How would I implement this?