From ca83c7fdedfa815f491a424ed34eb6e475d09e8d Mon Sep 17 00:00:00 2001 From: Dana Baghabrah Date: Sat, 4 Mar 2017 12:23:02 +0800 Subject: [PATCH 1/3] Add Storage Class --- src/seedu/addressbook/storage/Storage.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/seedu/addressbook/storage/Storage.java diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java new file mode 100644 index 000000000..682737a74 --- /dev/null +++ b/src/seedu/addressbook/storage/Storage.java @@ -0,0 +1,10 @@ +package seedu.addressbook.storage; +import seedu.addressbook.data.AddressBook; + +public abstract class Storage { + + public abstract void save(AddressBook addressBook) throws Exception; + public abstract AddressBook load() throws Exception; + public abstract String getPath(); + +} From 1c9b6e72df7eb540bf3790b24e9a1e5d21320d26 Mon Sep 17 00:00:00 2001 From: Dana Baghabrah Date: Sat, 4 Mar 2017 12:31:56 +0800 Subject: [PATCH 2/3] Invert dependency from Logic to Storage --- src/seedu/addressbook/logic/Logic.java | 15 ++++++++------- src/seedu/addressbook/storage/StorageFile.java | 2 +- src/seedu/addressbook/ui/Gui.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 17afd61a0..fb203b358 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -6,6 +6,7 @@ import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.parser.Parser; import seedu.addressbook.storage.StorageFile; +import seedu.addressbook.storage.Storage; import java.util.Collections; import java.util.List; @@ -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){ - setStorage(storageFile); + Logic(Storage storage, AddressBook addressBook){ + setStorage(storage); setAddressBook(addressBook); } - void setStorage(StorageFile storage){ + void setStorage(Storage storage){ this.storage = storage; } @@ -43,13 +44,13 @@ 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. + * @throws Storage.InvalidStorageFilePathException if the target file path is incorrect. */ - private StorageFile initializeStorage() throws StorageFile.InvalidStorageFilePathException { + private Storage initializeStorage() throws StorageFile.InvalidStorageFilePathException { return new StorageFile(); } - public String getStorageFilePath() { + public String getStoragePath() { return storage.getPath(); } 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"; diff --git a/src/seedu/addressbook/ui/Gui.java b/src/seedu/addressbook/ui/Gui.java index ed21989a4..396120b8f 100644 --- a/src/seedu/addressbook/ui/Gui.java +++ b/src/seedu/addressbook/ui/Gui.java @@ -31,7 +31,7 @@ public Gui(Logic logic, String version) { public void start(Stage stage, Stoppable mainApp) throws IOException { mainWindow = createMainWindow(stage, mainApp); - mainWindow.displayWelcomeMessage(version, logic.getStorageFilePath()); + mainWindow.displayWelcomeMessage(version, logic.getStoragePath()); } private MainWindow createMainWindow(Stage stage, Stoppable mainApp) throws IOException{ From a4ddb0c921492316d17537c5178fd2e6ed9aab6e Mon Sep 17 00:00:00 2001 From: Dana Baghabrah Date: Sat, 4 Mar 2017 21:10:23 +0800 Subject: [PATCH 3/3] Add Header Edit; --- src/seedu/addressbook/storage/Storage.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java index 682737a74..69073a812 100644 --- a/src/seedu/addressbook/storage/Storage.java +++ b/src/seedu/addressbook/storage/Storage.java @@ -1,10 +1,15 @@ package seedu.addressbook.storage; import seedu.addressbook.data.AddressBook; + +/** + * Represents the interface between Storagefile and logic in the address book. + */ + public abstract class Storage { public abstract void save(AddressBook addressBook) throws Exception; public abstract AddressBook load() throws Exception; public abstract String getPath(); - + }