Recommended sites

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Mediator Print E-mail
User Rating: / 1
PoorBest 
Thursday, 20 January 2005 21:38
Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.




Source code

/**
 * Each colleague knows its Mediator object. Communicates with its mediator
 * whenever it would have otherwise communicated with another colleague.
 * 
 * @role __Colleague
 */
public abstract class Colleague {
        /** my mediator */
        private Mediator mediator;        /** Create colleague which knows about supplied mediator */
        protected Colleague(Mediator mediator) {
                this.mediator = mediator;        }

        /** @return mediator this colleague knows about */
        public Mediator getMediator() {
                return mediator;        }

}

/** Concrete Colleague */
public class ConcreteColleagueA extends Colleague {
        public ConcreteColleagueA(Mediator mediator) {
                super(mediator);        }

        public void sampleOperation() {
                // some state changes occur,
                // notify mediator about them
                getMediator().changed(this);        }

}

/** Concrete Colleague */
public class ConcreteColleagueB extends Colleague {
        public ConcreteColleagueB(Mediator mediator) {
                super(mediator);        }

        public void sampleOperation() {
                // some state changes occur,
                // notify mediator about them
                getMediator().changed(this);        }

}

/**
 * Implements cooperative behavior by coordinating Colleague objects. Knows and
 * maintains its colleagues.
 */
public class ConcreteMediator implements Mediator {
        /** reference to concrete colleague */
        private ConcreteColleagueA aConcreteColleagueA;        /** reference to concrete colleague */
        private ConcreteColleagueB aConcreteColleagueB;        public void changed(Colleague colleague) {
                // handle changes of particular colleague
        }

        public void setConcreteColleagueA(ConcreteColleagueA colleague) {
                aConcreteColleagueA = colleague;        }

        public void setConcreteColleagueB(ConcreteColleagueB colleague) {
                aConcreteColleagueB = colleague;        }

}

/**
 * Defines an interface for communicating with Colleague objects.
 * 
 * @role __Mediator
 */
public interface Mediator {
        /** Colleagues calls this method to notify Mediator that something changed */
        void changed(Colleague colleague);}

Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Friday, 17 June 2005 23:39 )
 


Another articles:


Content View Hits : 2418574

Enter Amount: