publicabstractclassTempleClass { privatevoidstepOne() { System.out.println("This is step One from TempleClass"); } protectedvoidstepTwo() { System.out.println("This is step Two will be call by Child Temple with Overwrite"); } protected final voidstepThree() { System.out.println("This is step Three will be call by Child Temple without Overwrite"); } protectedabstractvoidTempleMethodOne(); protectedabstractvoidTempleMethodTwo(); publicvoidtemple(HookCallBack callback){ stepOne(); stepTwo(); stepThree(); TempleMethodOne(); TempleMethodTwo(); callback.methodFromHook(); } }
publicclassChildTempleClassOneextendsTempleClass { protectedvoidstepTwo() { System.out.println("This is from ChildTempleClassOne"); } protectedvoidTempleMethodOne() { System.out.println("This is from ChildTempleClassOne TempleMethodOne"); } protectedvoidTempleMethodTwo() { System.out.println("This is from ChildTempleClassOne TempleMethodTwo"); } }
publicclassChildTempleClassTwoextendsTempleClass { protectedvoidstepTwo() { System.out.println("This is from ChildTempleClassTwo"); } protectedvoidTempleMethodOne() { System.out.println("This is from ChildTempleClassTwo TempleMethodOne"); } protectedvoidTempleMethodTwo() { System.out.println("This is from ChildTempleClassTwo TempleMethodTwo"); } }
publicclassClient { publicstaticvoidmain(String args[]){ TempleClass temple1 = new ChildTempleClassOne(); TempleClass temple2 = new ChildTempleClassTwo(); temple1.temple(new HookCallBack() { publicvoidmethodFromHook() { System.out.println("This is from HookCallBack from temple1"); } }); temple2.temple(new HookCallBack() { publicvoidmethodFromHook() { System.out.println("This is from HookCallBack from temple2"); } }); } }