implement NamePrinter interface, see src/main/java/th/ac/kmitl/science/comsci/example/nameprinters/EarlyNamePrinter.java, or
Extend NamePrinterBase and override getName() to change the name, see src/main/java/th/ac/kmitl/science/comsci/example/nameprinters/NamePrinterBaseExampleNamePrinter.java
To print out a name to PrintWriter, pass a PrintWriter instance to NamePrinter.print()
To print out all NamePrinters in java.th.ac.kmitl.science.comsci.example.nameprinters package, you can use NamePrinterLoader to iterate through all NamePrinter.
how can you simplify your code and do it as guideline for your friends to follow up and extend the structure you define. (I think with this code they won't understand)
Changes
HelloServlet
to useNamePrinterLoader
to print names instead of hard-coded printing.Dependencies added
About NamePrinter
To create a
NamePrinter
, you have 2 optionsNamePrinter
interface, seesrc/main/java/th/ac/kmitl/science/comsci/example/nameprinters/EarlyNamePrinter.java
, orNamePrinterBase
and overridegetName()
to change the name, seesrc/main/java/th/ac/kmitl/science/comsci/example/nameprinters/NamePrinterBaseExampleNamePrinter.java
To print out a name to
PrintWriter
, pass aPrintWriter
instance toNamePrinter.print()
To print out all
NamePrinter
s injava.th.ac.kmitl.science.comsci.example.nameprinters
package, you can useNamePrinterLoader
to iterate through allNamePrinter
.