public classConcreComponentextendsAbsComponent{ public void OriginalComponent() { System.out.println("This is from OriginalComponent"); } }
public abstractclassAbsDecoratorextendsAbsComponent{ protectedAbsComponent component = null; public AbsDecorator(AbsComponent conponent) { this.component = conponent; } public void OriginalComponent() { component.OriginalComponent(); } }
public classConcreDecoratorextendsAbsDecorator{ public ConcreDecorator(AbsComponent conponent) { super(conponent); } public void selfFunction() { System.out.println("extend the original function with self function"); super.component.OriginalComponent(); } }
publicabstractclassAbstractStragryimplementsStragryInterface { protectedvoidcommonMethodOne() { System.out.println("This is common Method One"); } protectedvoidcommonMethodTwo() { System.out.println("This is common Method Two"); } publicabstractvoidstepOne(); publicabstractvoidstepTwo(); publicvoidstragryMethod() { stepOne(); stepTwo(); } }
public classConcreStragryOneextendsAbstractStragry{ public void stepOne() { System.out.println("This is from ConcreStragryOne"); super.commonMethodOne(); } @Override public void stepTwo() { System.out.println("This is from ConcreStragryOne"); super.commonMethodTwo(); } }
public classConcreStragryTwoextendsAbstractStragry{ public void stepOne() { System.out.println("This is from ConcreStragryTwo"); super.commonMethodOne(); } @Override public void stepTwo() { System.out.println("This is from ConcreStragryTwo"); super.commonMethodTwo(); } }
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"); } }); } }
public classRedefineAbstractextendsAbstractPart{ public RedefineAbstract(Implementor imp) { super(imp); } public void othersOperator() { System.out.println("Add some pre Operation"); super.otherOperator(); } }