Skip to content

Instantly share code, notes, and snippets.

View vnnvanhuong's full-sized avatar

Huong Nguyen vnnvanhuong

View GitHub Profile
//Which the same way to solve a problem
//Template Method uses Inheritance
//Strategy uses Composition/Delegation
abstract class TemplateMethod{
public final void execute() {
doFirstThing();
doSecondthing();
}
//modifier can be public, private, protected
abstract class AbstractDocumentGenerator{
//THIS IS TEMPLATE METHOD
public final File generate() {
Document defaultDocument = prepareDocumentByDefault();
Document refinedDocument = redefineDocument(defaultDocument);
String templatePath = getTemplatePath();
String outputName = getOutputName();
return DocFactory.generate(refinedDocument, templatePath, outputName);
}