diff options
author | wisberg <wisberg> | 2004-04-02 11:07:41 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2004-04-02 11:07:41 +0000 |
commit | e5ab0a5339aa52fe4a3810f18476806b65c0f222 (patch) | |
tree | fb518943cfb0a7a6eb9f7c316a6b0f4cd69b10ff /docs/sandbox | |
parent | 5c519477cbd4825b9b5683a0f24c244a5f65f86a (diff) | |
download | aspectj-e5ab0a5339aa52fe4a3810f18476806b65c0f222.tar.gz aspectj-e5ab0a5339aa52fe4a3810f18476806b65c0f222.zip |
Jan's 4/2 bug 50932 patch
Diffstat (limited to 'docs/sandbox')
22 files changed, 459 insertions, 61 deletions
diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/adapter/aspectj/Main.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/adapter/aspectj/Main.java index c544be6ed..3ffc6a083 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/adapter/aspectj/Main.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/adapter/aspectj/Main.java @@ -59,10 +59,12 @@ package ca.ubc.cs.spl.aspectPatterns.examples.adapter.aspectj; public class Main { /** - * the Adaptee in the scenario + * the Adaptee in the scenario. Note that our adaptee can be used as a + * Writer because of the <code>declare parents</code> statement in the + * aspect. */ - private static SystemOutPrinter adaptee; + private static Writer adaptee; /** * Implements the driver. diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Decoration.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Decoration.java new file mode 100644 index 000000000..c6d59e657 --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Decoration.java @@ -0,0 +1,44 @@ +package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; + +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +/** + * Implements a static method that returns a decorator string. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public class Decoration { + + /** + * Provides a decorator string consisting of stars ("*"). + * + * @returns a decorator string made up of stars + */ + + public static String getDecoration() { + return "*******************************************"; + } +}
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/FacadePolicyEnforcement.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/FacadePolicyEnforcement.java new file mode 100644 index 000000000..815793fd5 --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/FacadePolicyEnforcement.java @@ -0,0 +1,65 @@ +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; + +/** + * Enforces the encapsulation of the Facade by declaring a compile-time + * warning if the <i>subsystem</i> is accessed from any other class but the + * facade. We use <code>declare warning</code> here, but <code>declare error + * </code> can also be used. + * + * Instead of protecting the encapsulated subsystem against (only) mehod + * calls, other pointcut types (or combinations) could be used to achieve + * different effects. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public aspect FacadePolicyEnforcement { + + /** + * Enumerates all calls to encapsulated methods. It is of course easier + * to define this pointcut if the encapsulated subsystem is in a separate + * package, and the protected classes do not have to be enumerated. + */ + + pointcut callsToEncapsulatedMethods(): + call(* (Decoration || RegularScreen || StringTransformer).*(..)); + + /** + * Defines what constitutes legal accesses to the protected subsystem. + */ + + pointcut facade(): within(OutputFacade); + + /** + * Whenever a method in the encapsulated susbsystem is called, a compile + * time warning gets created - except if the method call comes from the + * <i>Facade</i> + */ + + declare warning: callsToEncapsulatedMethods() && !facade(): + "Calling encapsulated method directly - use Facade methods instead"; +} diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Main.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Main.java index 9d761685a..06e5ce34c 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Main.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Main.java @@ -29,24 +29,48 @@ package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; * subsystem. Facade defines a higher-level interface that makes the * subsystem easier to use.</i><p> * - * <p><i>This is the AspectJ version.</i><p> + * The <i>subsystem</i> consists of three classes that provide low-level + * string manipulation and output functionality: <code>RegularScreen</code>, + * <code>Decoration</code>, and <code>StringTransformer</code>. The <i>Facade + * </i> class <code>OutputFacade</code> procides a higher-level interface + * to output strings. This class calls methods on that higer-level interface. + * + * * <p><i>This is the AspectJ version.</i><p> * * For this pattern, both Java and AspectJ implementations are identical. - * The pattern introduces no crosscutting and is not abstractable. The - * java implementation is not duplicated here: All this class does is to - * print a message explaining that the versions are identical. + * The pattern introduces no crosscutting and is not abstractable. However, + * this example illustrates that AspectJ can be used to enforce the facade's + * encapsulation of the subsystem in question. Both <code>declare warning + * </code> and <code>declare error</code> can be used to that effect. * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/11/04 + * @version 1.11, 03/29/04 */ public class Main { - public static void main(String[] args) { - System.out.println("For this pattern, the AspectJ implementation "); - System.out.println("is identical to the Java implementation. It is "); - System.out.println("not duplicated here. "); - } + /** + * Tests the higher-level interface of <code>OutputFacade</code>. + * + * @param args Command-line parameters, ignored here + */ + + public static void main(String[] args) { + OutputFacade facade = new OutputFacade(); + + System.out.println("Testing regular Facade access..."); + facade.printDecoration(); + + facade.printNormal("Facade: this is normal printing"); + facade.printFancy ("Facade: this is fancy printing"); + + System.out.println("\nCircumventing Facade encapsulation..."); + + // Note that the compiler warning caused by the next line is + // intentional. See FacadePolicyEnforcement for details. + RegularScreen.print("It works, but should create a compiler warning"); + System.out.println(); + } }
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/OutputFacade.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/OutputFacade.java new file mode 100644 index 000000000..676e9e27b --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/OutputFacade.java @@ -0,0 +1,79 @@ +package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; + +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +/** + * Implements the <i>Facade</i> role in the pattern by providing a + * higher-level interface to the operations provided by + * <code>RegularScreen</code>, <code>Decoration</code>, + * and <code>StringTransformer</code>. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public class OutputFacade { + + /** + * Prints a string using <code>RegularScreen</code>. + * + * @param s the string to print + */ + + public void printNormal(String s) { + RegularScreen.print(s); + RegularScreen.newline(); + } + + /** + * Prints a two versions of string with decorations + * using <code>RegularScreen</code> and <code>Decoration</code>. + * + * @param s the string to print + */ + + public void printFancy(String s) { + printDecoration(); + + RegularScreen.print(StringTransformer.transformToUpper(s+" (uppercase)")); + RegularScreen.newline(); + + printDecoration(); + + RegularScreen.print(StringTransformer.transformToLower(s+" (lowercase)")); + RegularScreen.newline(); + + printDecoration(); + } + + /** + * Prints a decorator string. + */ + + public void printDecoration() { + RegularScreen.print(Decoration.getDecoration()); + RegularScreen.newline(); + RegularScreen.newline(); + } +}
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/RegularScreen.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/RegularScreen.java new file mode 100644 index 000000000..bbd623afe --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/RegularScreen.java @@ -0,0 +1,52 @@ +package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; + +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +/** + * Implements a low-level interface for printing to System.out. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public class RegularScreen { + + /** + * Prints a string to System.out. + * + * @param s the string to print + */ + + public static void print(String s) { + System.out.print(s); + } + + /** + * Prints a newline to System.out. + */ + + public static void newline() { + System.out.println(); + } +}
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/StringTransformer.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/StringTransformer.java new file mode 100644 index 000000000..a1f5eafba --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/StringTransformer.java @@ -0,0 +1,56 @@ +package ca.ubc.cs.spl.aspectPatterns.examples.facade.aspectj; + +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +/** + * Implements basic string manipulation facilities. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public class StringTransformer { + + /** + * Transforms a string to upper case + * + * @param s the string to transform + * @returns the transformed string + */ + + public static String transformToUpper(String s) { + return s.toUpperCase(); + } + + /** + * Transforms a string to lower case + * + * @param s the string to transform + * @returns the transformed string + */ + + public static String transformToLower(String s) { + return s.toLowerCase(); + } +}
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/java/Main.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/java/Main.java index 471babb90..36d7c0b4c 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/java/Main.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/java/Main.java @@ -39,13 +39,15 @@ package ca.ubc.cs.spl.aspectPatterns.examples.facade.java; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/11/04 + * @version 1.11, 04/29/04 */ public class Main { /** * Tests the higher-level interface of <code>OutputFacade</code>. + * + * @param args Command-line parameters, ignored here */ public static void main(String[] args) { diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/AlternateLabelCreatorImplementation.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/AlternateLabelCreatorImplementation.java new file mode 100644 index 000000000..d8966e882 --- /dev/null +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/AlternateLabelCreatorImplementation.java @@ -0,0 +1,62 @@ +package ca.ubc.cs.spl.aspectPatterns.examples.factoryMethod.aspectj; + +/* -*- 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.aspectPatterns. + * + * For more details and the latest version of this code, please see: + * http://www.cs.ubc.ca/labs/spl/projects/aodps.html + * + * Contributor(s): + */ + +import javax.swing.JLabel; +import javax.swing.JComponent; +/** + * This aspect changes the behavior of a <i>Factory Method</i> using + * <code>around</code> advice. With this approach it is possible to + * have the factories create different products depending on the + * aspects woven into the project. For example, this could be used + * as a very basic approach to software configuration management. + * + * In this case, two slightly different label products are produced, + * depending on whether this aspect is woven into the system or not. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 04/01/04 + */ + +public aspect AlternateLabelCreatorImplementation { + + /** + * Describes the factory method for which we want to + * modify the product + */ + + pointcut labelCreation(): + execution(JComponent LabelCreator.createComponent()); + + /** + * Creates the product, modifies it and passes the + * modified product on. + */ + + JComponent around(): labelCreation() { + JLabel label = (JLabel) proceed(); + label.setText("This is an alternate JLabel"); + return label; + } +}
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/CreatorImplementation.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/CreatorImplementation.java index 0e3692e72..0b8669cfc 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/CreatorImplementation.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/CreatorImplementation.java @@ -34,6 +34,7 @@ import java.awt.Point; * method <code>showFrame()</code>. The implementation is attached to the * <code>GUIComponentCreator</code> interface. With this approach, * <i>GUIComponentCreator</i> does not have to be an abstract class. + * * * @author Jan Hannemann * @author Gregor Kiczales diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ColorObserver.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ColorObserver.java index 5f06c7070..44af56c27 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ColorObserver.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ColorObserver.java @@ -31,7 +31,7 @@ import ca.ubc.cs.spl.aspectPatterns.patternLibrary.ObserverProtocol; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public aspect ColorObserver extends ObserverProtocol{ diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/CoordinateObserver.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/CoordinateObserver.java index 5b843e4ad..ea5c9635c 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/CoordinateObserver.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/CoordinateObserver.java @@ -30,7 +30,7 @@ import ca.ubc.cs.spl.aspectPatterns.patternLibrary.ObserverProtocol; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public aspect CoordinateObserver extends ObserverProtocol{ diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Main.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Main.java index ee36569a7..1e57db172 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Main.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Main.java @@ -50,7 +50,7 @@ import java.awt.Color; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public class Main { diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Point.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Point.java index 908dc6d3e..0709e59e5 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Point.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Point.java @@ -29,7 +29,7 @@ import java.awt.Color; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public class Point { @@ -68,7 +68,9 @@ public class Point { * @return the current x-coordinate */ - public int getX() { return x; } + public int getX() { + return x; + } /** * Returns the point's current y-coordinate. @@ -76,7 +78,9 @@ public class Point { * @return the current y-coordinate */ - public int getY() { return y; } + public int getY() { + return y; + } /** * Sets the current x-coordinate. @@ -84,7 +88,9 @@ public class Point { * @param x the new x-coordinate */ - public void setX(int x) { this.x=x; } + public void setX(int x) { + this.x = x; + } /** * Sets the current y-coordinate. @@ -92,7 +98,9 @@ public class Point { * @param y the new y-coordinate */ - public void setY(int y) { this.y=y; } + public void setY(int y) { + this.y = y; + } /** * Returns the point's current color. @@ -100,7 +108,9 @@ public class Point { * @return the current color */ - public Color getColor() { return color; } + public Color getColor() { + return color; + } /** * Sets the current color. @@ -108,5 +118,7 @@ public class Point { * @param color the new color */ - public void setColor(Color color) { this.color=color; } + public void setColor(Color color) { + this.color=color; + } } diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Screen.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Screen.java index bad74f3fa..13c1bd9bc 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Screen.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/Screen.java @@ -28,7 +28,7 @@ package ca.ubc.cs.spl.aspectPatterns.examples.observer.aspectj; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public class Screen { diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ScreenObserver.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ScreenObserver.java index ce5405797..1ee361928 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ScreenObserver.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/aspectj/ScreenObserver.java @@ -31,7 +31,7 @@ import ca.ubc.cs.spl.aspectPatterns.patternLibrary.ObserverProtocol; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public aspect ScreenObserver extends ObserverProtocol{ diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeObserver.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeObserver.java index 073156b72..21a7d58ff 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeObserver.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeObserver.java @@ -27,7 +27,7 @@ package ca.ubc.cs.spl.aspectPatterns.examples.observer.java; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public interface ChangeObserver { @@ -39,5 +39,5 @@ public interface ChangeObserver { * @param s the <i>Subject</i> triggering the update */ - public void update(ChangeSubject s); + public void refresh(ChangeSubject s); }
\ No newline at end of file diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeSubject.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeSubject.java index 60fb491b8..221cb53a0 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeSubject.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/ChangeSubject.java @@ -28,7 +28,7 @@ package ca.ubc.cs.spl.aspectPatterns.examples.observer.java; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public interface ChangeSubject { @@ -36,18 +36,18 @@ public interface ChangeSubject { /** * Attaches an <i>Observer</i> to this <i>Subject</i>. * - * @param o the <i>Observer</i> to attach + * @param o the <i>Observer</i> to add */ - public void attach(ChangeObserver o); + public void addObserver(ChangeObserver o); /** * Detaches an <i>Observer</i> from this <i>Subject</i>. * - * @param o the <i>Observer</i> to detach + * @param o the <i>Observer</i> to remove */ - public void detach(ChangeObserver o); + public void removeObserver(ChangeObserver o); /** * Notifies all <i>Observer</i>s. diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Main.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Main.java index fbd1bc0a3..8cfac7b4b 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Main.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Main.java @@ -75,12 +75,7 @@ import java.awt.Color; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 - * - * @see Point - * @see Adaptee - * @see Observer - * @see Subject + * @version 1.11, 04/01/04 */ public class Main { @@ -119,14 +114,14 @@ public class Main { System.out.println("- s3 and s4 observe coordinate changes to p"); System.out.println("- s5 observes s2's and s4's display() method"); - p.attach(s1); - p.attach(s2); + p.addObserver(s1); + p.addObserver(s2); - p.attach(s3); - p.attach(s4); + p.addObserver(s3); + p.addObserver(s4); - s2.attach(s5); - s4.attach(s5); + s2.addObserver(s5); + s4.addObserver(s5); System.out.println("Changing p's color:"); diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Point.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Point.java index 94060fce1..2a4322bb3 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Point.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Point.java @@ -31,7 +31,7 @@ import java.util.Iterator; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public class Point implements ChangeSubject { @@ -65,8 +65,8 @@ public class Point implements ChangeSubject { */ public Point(int x, int y, Color color) { - this.x=x; - this.y=y; + this.x = x; + this.y = y; this.color=color; this.observers = new HashSet(); } @@ -77,7 +77,9 @@ public class Point implements ChangeSubject { * @return the current x-coordinate */ - public int getX() { return x; } + public int getX() { + return x; + } /** * Returns the point's current y-coordinate. @@ -85,7 +87,9 @@ public class Point implements ChangeSubject { * @return the current y-coordinate */ - public int getY() { return y; } + public int getY() { + return y; + } /** * Sets the current x-coordinate. @@ -94,7 +98,7 @@ public class Point implements ChangeSubject { */ public void setX(int x) { - this.x=x; + this.x = x; notifyObservers(); } @@ -105,7 +109,7 @@ public class Point implements ChangeSubject { */ public void setY(int y) { - this.y=y; + this.y = y; notifyObservers(); } @@ -124,7 +128,7 @@ public class Point implements ChangeSubject { */ public void setColor(Color color) { - this.color=color; + this.color = color; notifyObservers(); } @@ -135,7 +139,7 @@ public class Point implements ChangeSubject { * @param o the <i>Observer</i> to attach */ - public void attach(ChangeObserver o) { + public void addObserver(ChangeObserver o) { this.observers.add(o); } @@ -145,7 +149,7 @@ public class Point implements ChangeSubject { * @param o the <i>Observer</i> to detach */ - public void detach(ChangeObserver o) { + public void removeObserver(ChangeObserver o) { this.observers.remove(o); } @@ -155,7 +159,7 @@ public class Point implements ChangeSubject { public void notifyObservers() { for (Iterator e = observers.iterator() ; e.hasNext() ;) { - ((ChangeObserver)e.next()).update(this); + ((ChangeObserver)e.next()).refresh(this); } } } diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Screen.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Screen.java index 9259d01a7..1860b477b 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Screen.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/observer/java/Screen.java @@ -31,7 +31,7 @@ import java.util.Iterator; * * @author Jan Hannemann * @author Gregor Kiczales - * @version 1.1, 02/13/04 + * @version 1.11, 04/01/04 */ public class Screen implements ChangeSubject, ChangeObserver { @@ -79,7 +79,7 @@ public class Screen implements ChangeSubject, ChangeObserver { * @param o the <i>Observer</i> to attach */ - public void attach(ChangeObserver o) { + public void addObserver(ChangeObserver o) { this.observers.add(o); } @@ -89,7 +89,7 @@ public class Screen implements ChangeSubject, ChangeObserver { * @param o the <i>Observer</i> to detach */ - public void detach(ChangeObserver o) { + public void removeObserver(ChangeObserver o) { this.observers.remove(o); } @@ -99,7 +99,7 @@ public class Screen implements ChangeSubject, ChangeObserver { public void notifyObservers() { for (Iterator e = observers.iterator() ; e.hasNext() ;) { - ((ChangeObserver)e.next()).update(this); + ((ChangeObserver)e.next()).refresh(this); } } @@ -113,7 +113,7 @@ public class Screen implements ChangeSubject, ChangeObserver { * @param s the <i>Subject</i> triggering the update */ - public void update(ChangeSubject s) { + public void refresh(ChangeSubject s) { String subjectTypeName = s.getClass().getName(); subjectTypeName = subjectTypeName.substring( subjectTypeName.lastIndexOf(".")+1, subjectTypeName.length()); diff --git a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/patternLibrary/StrategyProtocol.java b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/patternLibrary/StrategyProtocol.java index 8ce60f4fc..0e3291460 100644 --- a/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/patternLibrary/StrategyProtocol.java +++ b/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/patternLibrary/StrategyProtocol.java @@ -32,7 +32,7 @@ import java.util.Hashtable; * given <i>Context</i>. * * It is also possible (although not shown here) to provide abstract - * pointcust for setting or removing <i>Strategy</i>s from + * pointcuts for setting or removing <i>Strategy</i>s from * <i>Context</>s. This would allow <i>Client</i> implementations * to be free of pattern code. For an example of how to do that, * see the implementation of the abstract CommandProtocol aspect. |