Big talk Design Pattern _ intermediary Pattern

Source: Internet
Author: User

Us and Iraq calls will be passed through the United Nations Security Council.

Package COM. WZS. design;/*** big talk design mode -- page262 intermediary mode ** @ author administrator **/public class mediatorpattern {public static void main (string [] ARGs) {unitednationssecuritycouncer UNSC = new unitednationssecuritycouncer (); USA C1 = new USA (UNSC); Iraq C2 = new Iraq (UNSC); UNSC. setcolleague1 (C1); UNSC. setcolleague2 (C2); c1.declare ("developers and weapons are not allowed; otherwise, a war is required! "); C2.declare (" We have no nuclear weapons and are not afraid of aggression. ") ;}// Country class abstract class country {protected UnitedNations mediator; Public Country (UnitedNations mediator) {This. mediator = mediator; }}// U.S. class USA extends country {public USA (UnitedNations mediator) {super (mediator);} public void declare (string message) {mediator. declare (message, this);} public void getmessage (string message) {system. out. println ("US gets peer information:" + message) ;}// Iraqi class Iraq extends country {public Iraq (UnitedNations mediator) {super (mediator );} public void declare (string message) {mediator. declare (message, this);} public void getmessage (string message) {system. out. println ("Iraq obtains peer information:" + message) ;}// United Nations machine structure Abstract class UnitedNations {public abstract void declare (string message, country colleague );} // United Nations Security Council class unitednationssecuritycouncel extends UnitedNations {private USA colleague1; private Iraq colleague2; // US public void setcolleague1 (USA colleague1) {This. colleague1 = colleague1;} // Iraqi public void setcolleague2 (Iraq colleague2) {This. colleague2 = colleague2;} @ overridepublic void declare (string message, country colleague) {If (colleague = colleague1) {colleague1.getmessage (Message );} else {colleague2.getmessage (Message );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.