@@ -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. |
@@ -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 "*******************************************"; | |||
} | |||
} |
@@ -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"; | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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) { |
@@ -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; | |||
} | |||
} |
@@ -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 |
@@ -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{ |
@@ -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{ |
@@ -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 { |
@@ -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; | |||
} | |||
} |
@@ -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 { |
@@ -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{ |
@@ -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); | |||
} |
@@ -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. |
@@ -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:"); | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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()); |
@@ -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. |