/** * Created by hero on 17-2-21. */ publicabstractclassPerson { publicabstractvoidgetAttitude(Aspect aspect); }
1 2 3 4 5 6 7 8 9 10 11 12
package visitor;
/** * Created by hero on 17-2-21. */ publicclassManextendsPerson{ @Override publicvoidgetAttitude(Aspect aspect) { aspect.getManAttitude(this); } }
1 2 3 4 5 6 7 8 9 10 11 12
package visitor;
/** * Created by hero on 17-2-21. */ publicclassWomanextendsPerson { @Override publicvoidgetAttitude(Aspect aspect) { aspect.getWomanAttitude(this); } }
1 2 3 4 5 6 7 8 9 10
package visitor;
/** * Created by hero on 17-2-21. */ publicabstractclassAspect { publicabstractvoidgetManAttitude(Man man); publicabstractvoidgetWomanAttitude(Woman woman); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package visitor;
/** * Created by hero on 17-2-21. */ publicclassLoveextendsAspect { @Override publicvoidgetManAttitude(Man man) { System.out.println("男人恋爱时,凡事不懂也要装懂"); }