Skip to content

Instantly share code, notes, and snippets.

@priyankahdp
Created April 9, 2023 20:29
Show Gist options
  • Save priyankahdp/4df909f2c8a0b3d5908c5dd466fb9c05 to your computer and use it in GitHub Desktop.
Save priyankahdp/4df909f2c8a0b3d5908c5dd466fb9c05 to your computer and use it in GitHub Desktop.
template-pattern
package com.designpatterns.template;
public class WashineMachineApplication {
public static void main(String[] args) {
WashineMachineProcess wmProcess = new WashineMachineProcessor();
wmProcess.run();
}
}
package com.designpatterns.template;
//defines the algorithm's skeleton
public abstract class WashineMachineProcess {
public final void run() {
switchOn();
openLid();
insertClothes();
insertWashingPowder();
closeLid();
pressStartButton();
}
protected abstract void switchOn();
protected abstract void openLid();
protected abstract void insertClothes();
protected abstract void insertWashingPowder();
protected abstract void closeLid();
protected abstract void pressStartButton();
}
package com.designpatterns.template;
public class WashineMachineProcessor extends WashineMachineProcess {
@Override
protected void switchOn() {
System.out.println("switchOn function");
}
@Override
protected void openLid() {
System.out.println("openLid function");
}
@Override
protected void insertClothes() {
System.out.println("insertClothes function");
}
@Override
protected void insertWashingPowder() {
System.out.println("insertWashingPowder function");
}
@Override
protected void closeLid() {
System.out.println("closeLid function");
}
@Override
protected void pressStartButton() {
System.out.println("pressStartButton function");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment