//飞机 public class Plane { public void buyTicket(){ System.out.println("订购飞机票"); } } //火车 public class Train { public void buyTicket(){ System.out.println("订购火车票"); } } //景点 public class Scenery { public void buyTicket(){ System.out.println("购买景点门票"); } } //旅游公司(门面对象) public class TripCompany { private Plane plane; private Train train; private Scenery scenery; public TripCompany() { plane=new Plane(); train=new Train(); scenery=new Scenery(); } //报团旅游 public void orderTrip(){ plane.buyTicket();//买飞机票 train.buyTicket();//买火车票 scenery.buyTicket();//买景点门票 } //用户也可以只订购机票 public void buyPlaneTicket(){ plane.buyTicket(); } //用户也可以只订购火车票 public void buyTrainTicket(){ train.buyTicket(); } //用户也可以只订购景点门票 public void buySceneryTicket(){ scenery.buyTicket(); } } public class Test { public static void main(String[] args) { TripCompany tripCompany = new TripCompany();//旅游公司 tripCompany.orderTrip();//用户报团旅游 tripCompany.buyPlaneTicket();//也有用户只是想在旅游公司网订机票 tripCompany.buyTrainTicket();//也有用户只想在旅游公司订火车票 tripCompany.buySceneryTicket();//也有用户只想在旅游公司买景点门票 } }