RSS feed
[root]
/
document
/
software design
/
Design pattern example in aspect programming
/
library
/
pattern
/
spl
/
cs
/
ubc
/
ca
login:
password:
title search:
Search this site
Enter your search terms
Web
www.carfield.com.hk
Submit search form
Prev
Next
Wed Mar 24 16:00:00 GMT 2004
MediatorProtocol
package ca.ubc.cs.spl.pattern.library; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ import java.util.WeakHashMap; import java.util.Collection; import java.util.LinkedList; import java.util.Iterator; /** * Defines the general behavior of the mediator design pattern. * * Each concrete sub-aspect of MediatorProtocol defines one kind of mediation * relationship. Within that kind of relationship, there can be any number * of <i>Colleague</i>s. * * The sub-aspect defines three things: <ol> * * <li> what types can be colleagues and mediator <br> * this is done using +implements * * <li> what operations on the colleague require notifying the mediator<br> * this is done by concretizing the change(Colleague) pointcut * * <li> how to update the observers <br> * this is done by defining a method on * updateObserver(Subject, Observer) * </ol> * * Note that in this implementation, the work of updating is a method * on the sub-aspect, not a method introduced on the observer. This * allows one class of object to be the observer in different kinds of * observing relationships, each of which has a different updating * behavior. For observers that just have a single generic update * behavior, the method on updateObserver will just be a simple call * that generic updater. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 * */ public abstract aspect MediatorProtocol { /** * Assings the <code>Subject</code> role to the <code>Point</code> class. * Roles are modeled as (empty) interfaces. */ protected interface Colleague { } /** * Assings the <code>Subject</code> role to the <code>Point</code> class. * Roles are modeled as (empty) interfaces. */ protected interface Mediator { } /** * Stores the mapping between <code>Colleagues</code>s and <code> * Mediator</code>s. For each colleague, its <code>Mediator</code> * is stored. */ private WeakHashMap mappingColleagueToMediator = new WeakHashMap(); /** * Returns the <code>Mediator</code> of * a particular colleague. Used internally. * * @param colleague the colleague for which to return the mediator * @return the <code>Mediator</code> of the colleague */ private Mediator getMediator(Colleague colleague) { Mediator mediator = (Mediator) mappingColleagueToMediator.get(colleague); return mediator; } /** * Sets the mediator for a colleague. This is a method on the pattern * aspect, not the subject. * * @param colleague the colleague to set a new mediator for * @param mediator the new mediator to set */ public void setMediator(Colleague c, Mediator m) { mappingColleagueToMediator.put(c, m); } /** * Defines what changes on Colleagues cause their mediator to be notified * * @param cs the colleague on which the change occured */ protected abstract pointcut change(Colleague c); /** * Call updateObserver to update each observer. */ after(Colleague c): change(c) { notifyMediator(c, getMediator(c)); } /** * Defines how the <code>Mediator</code> is to be updated when a change * to a <code>Colleague</code> occurs. To be concretized by sub-aspects. * * @param c the colleague on which a change of interest occured * @param m the mediator to be notifed of the change */ protected abstract void notifyMediator(Colleague c, Mediator m); }
(google search)
(amazon search)
1
2
3
second
download zip of files only
Prev
Next