I have a Java question and I can't see how I can implement the methods correctly. I am not very good with architecture.
Data Manager interface class:
public interface DataManager {
public void readData();
public void writeData();
}
Data abstract class:
public abstract class Data implements DataManager {
@Override
public void readData() {};
@Override
public void writeData() {};
}
Data Reader class:
public class DataReader extends Data {
// I want to implement the readData() here
}
Data Writer class:
public class DataWriter extends Data {
// I want to implement the writeData() here
}
If I want to implement the readData() and writeData() separately in two different classes with only one interface, is it possible? I don't know why I am doing this way. Maybe it just looks cleaner and easier when I add more methods to the reader or writer class. Should I implement everything in just one single class?
I want this library to allow users using the manager object to have access for data reading and writing. But for implementation, I don't know how I can do it correctly.
DataManagermust implement both methods. You can have an empty implementation (like in your abstract class), but it would be better to split it into two interfaces if you intend for them to be implemented separately.DataManagerclass that tookDataReaderandDataWriterclasses as constructor arguments, and passed the implementation off to them. I think that might be close to what you're aiming for?readandwritemethods in theDataManagerclass would be very small "wrapper" methods for calls to theDataReaderandDataWriterobjects it was passed. This meant that if you had some set of different Writers and some set of different Readers, you could easily make a Manager out of any combination of them.