Open seanlim opened 1 day ago
The way I'm thinking of doing this is similar to the way it is being done for Storage
:
Add an interface
to the current model abstraction chain, similar to what's being done for storage:
/**
* Represents a storage for {@link AddressBook}.
*/
public interface AddressBookStorage {
...
}
/**
* A class to access AddressBook data stored as a json file on the hard disk.
*/
public class JsonAddressBookStorage implements AddressBookStorage {
...
}
/**
* Represents a storage for {@link UserPrefs}.
*/
public interface UserPrefsStorage {
...
}
/**
* A class to access UserPrefs stored in the hard disk as a json file
*/
public class JsonUserPrefsStorage implements UserPrefsStorage {
...
}
We use these interfaces to create a new Mother-of-all Model
interface, which we implement as ModelManager
, which can be initialised with instances of AddressBookModel
and TransactionBookModel
.
Here is how Storage
does it:
/**
* API of the Storage component
*/
public interface Storage extends AddressBookStorage, UserPrefsStorage {
...
}
public class StorageManager implements Storage {
// Initialise with instance of each storage
private AddressBookStorage addressBookStorage;
private UserPrefsStorage userPrefsStorage;
// Expose all methods from all storages
@Override
public Optional<UserPrefs> readUserPrefs() throws DataLoadingException {
return userPrefsStorage.readUserPrefs();
}
@Override
public Optional<ReadOnlyAddressBook> readAddressBook(Path filePath) throws DataLoadingException {
return addressBookStorage.readAddressBook(filePath);
}
...
}
The current way we have split our models makes it very hard to share data across different components from
address
andtransaction
. We might possibly want to add a generalisedmodel
that implements bothaddress.model
andtransaction.model
.