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
VisitorProtocol
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.pattern. * * Contributor(s): */ /** * Implements the abstracted Visitor design pattern.<p> * * Intent: <i>Represents an operation to be performed on the elements of an * object structure. Visitor lets you define a new operation without changing * the classes of the elements on which it operates</i><p> * * This code defines the roles <code>VisitorNode</code>, <code>VRegularNode * </code>, and <code>VLeaf</code>, representing a general node interface, * a non-terminal binary tree node, and a terminal node, respectively. * This aspect attaches default implementations of the various * <code>accept(..)</code> methods to the (abstract) participants. Concrete * subaspects just have to assign roles. Concrete Visitors implement the * inner interface <code>NodeVisitor</code>. <p> * * Note that this implementation only deals with two different kind of nodes: * terminal and non-terminal nodes. In cases where the aggregate structure * contains more types of nodes, this aspect cannot be used without * modifications. <p> * * Note further that whenever the aggregate structure is unimportant, the * additional functionality can be added using AspectJ's open classes * mechanism, i.e. by simply attaching the new methods to existing classes. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 06/13/02 */ public abstract aspect VisitorProtocol { /** * Defines the <i>Element</i> role. The inerface is public so that * concrete visitors can use the type. */ public interface VisitorNode {} /** * Defines a <i>ConcreteElement</i> role for non-terminal nodes in * a binary tree structure. The inerface is protected as it is only used * bu concrete subaspects. */ protected interface VRegularNode extends VisitorNode {} /** * Defines a <i>ConcreteElement</i> role for terminal nodes in * a tree structure. The inerface is protected as it is only used * bu concrete subaspects. */ protected interface VLeaf extends VisitorNode {} /** * This inerface is implemented by <i>ConcreteVisitor</i>s. */ public interface NodeVisitor { /** * Defines a method signature for visiting regular nodes. * * @param node the regular node to visit */ public void visitRegularNode(VisitorNode node); /** * Defines a method signature for visiting leaf nodes. * * @param node the leaf node to visit */ public void visitLeaf(VisitorNode node); /** * Defines a method signature for returning the visitor's results * * @param node a string containig the visitor's results */ public String report(); } /** * Attaches the <code>accept(..)</code> code to nodes * * @param nv the visitor that is to be accepted */ public void VisitorNode.accept(NodeVisitor nv) {} /** * Attaches the <code>accept(..)</code> code to regular nodes * * @param nv the visitor that is to be accepted */ public void VRegularNode.accept(NodeVisitor nv) { nv.visitRegularNode(this); } /** * Attaches the <code>accept(..)</code> code to leaf nodes * * @param nv the visitor that is to be accepted */ public void VLeaf.accept(NodeVisitor nv) { nv.visitLeaf(this); } }
(google search)
(amazon search)
1
2
3
second
download zip of files only
Prev
Next