Here are the things you should be able to do after studying this code and completing the corresponding exercises.
- A member of the
CommandResult
class is not encapsulated. i.e. it is visible outside the object. Hide it so that it can only be accessed using methods provided.
- Assume the address is entered in the following format
a/BLOCK, STREET, UNIT, POSTAL_CODE
e.g.a/123, Clementi Ave 3, #12-34, 231534
- Split the
Address
class as follows.
- Update the user guide and tests to match.
The Single Responsibility Principle (SRP) states that a class should have only one reason to change. The code given follows SRP to a reasonable extent, but there are places where it can be applied further.
The exercise in the LO-ImplementClass
section is somewhat related to SRP as well.
Here's a slightly more difficult exercise.
TextUi
class has more than one responsibility. Try to extract out the responsibility of Formatting text for display (e.g. adding decorations) in to a separate class namedFormatter
.
- An explanation of the SRP from www.oodesign.com
- Another explanation (more detailed) by Patkos Csaba
- A book chapter on SRP by Robert C. Martin
- The current code does not handle the situation where the user deletes the storage file while the AddressBook program is running. Use exceptions to handle that situation.
Coming soon ...