diff --git a/doc/Diagrams.pptx b/doc/Diagrams.pptx index 1d9a5867d..624db2e62 100644 Binary files a/doc/Diagrams.pptx and b/doc/Diagrams.pptx differ diff --git a/doc/LearningOutcomes.md b/doc/LearningOutcomes.md index e4bf5f468..a631b9df3 100644 --- a/doc/LearningOutcomes.md +++ b/doc/LearningOutcomes.md @@ -6,6 +6,7 @@ After studying this code and completing the corresponding exercises, you should 1. [Use Non Functional Requirements `[LO-NFR]`](#use-non-functional-requirements-lo-nfr) 1. [Use Polymorphism `[LO-Polymorphism]`](#use-polymorphism-lo-polymorphism) 1. [Use abstract classes/methods `[LO-Abstract]`](#use-abstract-classesmethods-lo-abstract) +1. [Use interfaces `[LO-Interfaces]`](#use-interfaces-lo-interfaces) 1. [Follow Liskov Substitution Principle `[LO-LSP]`](#follow-liskov-substitution-principle-lo-lsp) 1. [Use Java-FX for GUI programming `[LO-JavaFx]`](#use-java-fx-for-gui-programming-lo-javafx) 1. [Analyze Coupling and Cohesion of designs `[LO-CouplingCohesion]`](#analyze-coupling-and-cohesion-of-designs-lo-couplingcohesion) @@ -88,6 +89,39 @@ Note: There may be better ways to limit file saving to commands that mutate data ------------------------------------------------------------------------------------------------------ +## Use interfaces `[LO-Interfaces]` + +Note how the `Person` class implements the `ReadOnlyPerson` interface so that clients who don't need write access to `Person` objects can access `Person` objects through the `ReadOnlyPerson` interface instead. + + +#### References + +* [se-edu/se-book: Implementation: OOP: Abstract Interfaces](https://se-edu.github.io/se-book/oopImplementation/interfaces/) + +##### Exercise: Add a `Printable` interface + +* Add a `Printable` interface as follows.
+ +* `Override` the `getPrintableString` in classes `Name`, `Phone`, `Email`, and `Address` so that each produces a printable string representation of the object. e.g. `Name: John Smith`, `Phone: 12349862` +* Add the following method in a suitable place of some other class. Note how the method depends on the Interface. + + ```java + /** + * Returns a concatenated version of the printable strings of each object. + */ + String getPrintableString(Printable... printables){ + ``` + + The above method can be used to get a printable string representing a bunch of person details. + For example, you should be able to call that method like this: + + ```java + //p is a Person object + return getPrintableString(p.getPhone(), p.getEmail(), p.getAddress()); + ``` + +------------------------------------------------------------------------------------------------------ + ## Follow Liskov Substitution Principle `[LO-LSP]` #### References diff --git a/doc/images/PrintableInterface.png b/doc/images/PrintableInterface.png new file mode 100644 index 000000000..d7a69936b Binary files /dev/null and b/doc/images/PrintableInterface.png differ diff --git a/doc/images/ReadOnlyPersonUsage.png b/doc/images/ReadOnlyPersonUsage.png new file mode 100644 index 000000000..4c2530126 Binary files /dev/null and b/doc/images/ReadOnlyPersonUsage.png differ