From 4ce66bfaa0152b239de337d259c45ed8d546a211 Mon Sep 17 00:00:00 2001 From: dylansyj Date: Wed, 1 Mar 2017 05:09:29 +0800 Subject: [PATCH] Added abstract class Storage that allows interaction between Logic and StorageFile class --- src/seedu/addressbook/logic/Logic.java | 9 +++++---- src/seedu/addressbook/storage/Storage.java | 14 ++++++++++++++ src/seedu/addressbook/storage/StorageFile.java | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/seedu/addressbook/storage/Storage.java diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 17afd61a0..9ba68976f 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -5,6 +5,7 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.parser.Parser; +import seedu.addressbook.storage.Storage; import seedu.addressbook.storage.StorageFile; import java.util.Collections; @@ -17,7 +18,7 @@ public class Logic { - private StorageFile storage; + private Storage storage; private AddressBook addressBook; /** The list of person shown to the user most recently. */ @@ -28,12 +29,12 @@ public Logic() throws Exception{ setAddressBook(storage.load()); } - Logic(StorageFile storageFile, AddressBook addressBook){ + Logic(Storage storageFile, AddressBook addressBook){ setStorage(storageFile); setAddressBook(addressBook); } - void setStorage(StorageFile storage){ + void setStorage(Storage storage){ this.storage = storage; } @@ -45,7 +46,7 @@ void setAddressBook(AddressBook addressBook){ * Creates the StorageFile object based on the user specified path (if any) or the default storage path. * @throws StorageFile.InvalidStorageFilePathException if the target file path is incorrect. */ - private StorageFile initializeStorage() throws StorageFile.InvalidStorageFilePathException { + private Storage initializeStorage() throws StorageFile.InvalidStorageFilePathException { return new StorageFile(); } diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java new file mode 100644 index 000000000..65d4e4706 --- /dev/null +++ b/src/seedu/addressbook/storage/Storage.java @@ -0,0 +1,14 @@ +package seedu.addressbook.storage; + +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.storage.StorageFile.StorageOperationException; + +public abstract class Storage { + + public abstract String getPath(); + + public abstract AddressBook load() throws StorageOperationException; + + public abstract void save(AddressBook addressBook) throws StorageOperationException; + +} diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 693097a86..4a1132c52 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -15,7 +15,7 @@ /** * Represents the file used to store address book data. */ -public class StorageFile { +public class StorageFile extends Storage{ /** Default file path used if the user doesn't provide the file name. */ public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt";