From e5ab0a5339aa52fe4a3810f18476806b65c0f222 Mon Sep 17 00:00:00 2001 From: wisberg Date: Fri, 2 Apr 2004 11:07:41 +0000 Subject: [PATCH] Jan's 4/2 bug 50932 patch --- .../examples/adapter/aspectj/Main.java | 6 +- .../examples/facade/aspectj/Decoration.java | 44 +++++++++++ .../aspectj/FacadePolicyEnforcement.java | 65 +++++++++++++++ .../examples/facade/aspectj/Main.java | 44 ++++++++--- .../examples/facade/aspectj/OutputFacade.java | 79 +++++++++++++++++++ .../facade/aspectj/RegularScreen.java | 52 ++++++++++++ .../facade/aspectj/StringTransformer.java | 56 +++++++++++++ .../examples/facade/java/Main.java | 4 +- .../AlternateLabelCreatorImplementation.java | 62 +++++++++++++++ .../aspectj/CreatorImplementation.java | 1 + .../observer/aspectj/ColorObserver.java | 2 +- .../observer/aspectj/CoordinateObserver.java | 2 +- .../examples/observer/aspectj/Main.java | 2 +- .../examples/observer/aspectj/Point.java | 26 ++++-- .../examples/observer/aspectj/Screen.java | 2 +- .../observer/aspectj/ScreenObserver.java | 2 +- .../observer/java/ChangeObserver.java | 4 +- .../examples/observer/java/ChangeSubject.java | 10 +-- .../examples/observer/java/Main.java | 19 ++--- .../examples/observer/java/Point.java | 26 +++--- .../examples/observer/java/Screen.java | 10 +-- .../patternLibrary/StrategyProtocol.java | 2 +- 22 files changed, 459 insertions(+), 61 deletions(-) create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/Decoration.java create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/FacadePolicyEnforcement.java create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/OutputFacade.java create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/RegularScreen.java create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/facade/aspectj/StringTransformer.java create mode 100644 docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/aspectj/AlternateLabelCreatorImplementation.java 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 declare parents 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 subsystem is accessed from any other class but the + * facade. We use declare warning here, but declare error + * 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 + * Facade + */ + + 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.

* - *

This is the AspectJ version.

+ * The subsystem consists of three classes that provide low-level + * string manipulation and output functionality: RegularScreen, + * Decoration, and StringTransformer. The Facade + * class OutputFacade procides a higher-level interface + * to output strings. This class calls methods on that higer-level interface. + * + * *

This is the AspectJ version.

* * 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 declare warning + * and declare error 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 OutputFacade. + * + * @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 Facade role in the pattern by providing a + * higher-level interface to the operations provided by + * RegularScreen, Decoration, + * and StringTransformer. + * + * @author Jan Hannemann + * @author Gregor Kiczales + * @version 1.11, 03/29/04 + */ + +public class OutputFacade { + + /** + * Prints a string using RegularScreen. + * + * @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 RegularScreen and Decoration. + * + * @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 OutputFacade. + * + * @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 Factory Method using + * around 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 showFrame(). The implementation is attached to the * GUIComponentCreator interface. With this approach, * GUIComponentCreator 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 Subject 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 Observer to this Subject. * - * @param o the Observer to attach + * @param o the Observer to add */ - public void attach(ChangeObserver o); + public void addObserver(ChangeObserver o); /** * Detaches an Observer from this Subject. * - * @param o the Observer to detach + * @param o the Observer to remove */ - public void detach(ChangeObserver o); + public void removeObserver(ChangeObserver o); /** * Notifies all Observers. 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 Observer 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 Observer 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 Observer 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 Observer 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 Subject 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 Context. * * It is also possible (although not shown here) to provide abstract - * pointcust for setting or removing Strategys from + * pointcuts for setting or removing Strategys from * Contexts. This would allow Client implementations * to be free of pattern code. For an example of how to do that, * see the implementation of the abstract CommandProtocol aspect. -- 2.39.5