<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mwroda</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mwroda"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Mwroda"/>
	<updated>2026-06-01T22:51:27Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43415</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43415"/>
		<updated>2010-12-11T03:58:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern], also known as the [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse problem] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] with inheritance when a base class contains methods which invalidate the derived class, and thereby violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle].&lt;br /&gt;
&lt;br /&gt;
[[Image:Square-rectangle.gif|250px]]&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square. By the 'is a' test, one might reasonably define the Square class as a specialization of the Rectangle class (Square is a Rectangle), where all sides are of equal length.  But suppose Rectangle defines a constructor that takes two arguments, x and y, for the lengths of the sides. How can Square provide an implementation for this constructor?  If the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
The situation is worse for modifier methods on the base class. Suppose Rectangle has a method setX which modifies only two sides of the rectangle. When called on a Square, it would cause the object to no longer be a square. This can be particularly problematic when new modifiers are added to an existing base class after it has been subclassed. If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following example illustrates the problem. In this case, Square has decided not to implement a constructor defined in Rectangle. But there is still a problem with the setX modifier:&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void print() {&lt;br /&gt;
          System.out.println(this.getClass().getName() + &amp;quot; has sides of length &amp;quot; + x + &amp;quot; and &amp;quot; + y);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public static void main(String[] args) {&lt;br /&gt;
          Square s = new Square(10);&lt;br /&gt;
          s.print();&lt;br /&gt;
          s.setX(5);&lt;br /&gt;
          s.print();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This produces the following output:&lt;br /&gt;
&lt;br /&gt;
  Square has sides of length 10 and 10&lt;br /&gt;
  Square has sides of length 5 and 10&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
  public class Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int x;&lt;br /&gt;
  &lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  class Rectangle extends Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Hidden constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could choose to not provide an implementation for the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This design maybe controversial since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) { }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) {&lt;br /&gt;
         throw new UnsupportedOperationException();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
In Java the [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/UnsupportedOperationException.html UnsupportedOperationException] could be thrown, which is a [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/RuntimeException.html RuntimeException] and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.[1] The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          super(x, x);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
When a method is called that will mutate the object, the implementation could instantiate an instance of the base class and return that instead[1]. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          super(x, x);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          if (x == this.y)&lt;br /&gt;
              return super(x);&lt;br /&gt;
          else&lt;br /&gt;
              return new Rectangle(x);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Use separate immutable and mutable classes ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the Rectangle class is [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore its methods cannot change derived instances, they can only return new instances of Rectangle.  A separate MutableRectangle class could be defined and all the modifiers put into it.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  class ImmutableRectangle extends Rectangle&lt;br /&gt;
  {&lt;br /&gt;
      public Rectangle() { super(); }&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          super(x, y);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private void setX(int x) { }&lt;br /&gt;
  &lt;br /&gt;
      private void setY(int y) { }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends ImmutableRectangle &lt;br /&gt;
  {&lt;br /&gt;
      ...&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
=== Initialize base class as mutable/immutable ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the above but not requiring separate mutable and immutable classes. Rectangle could be initialized, presumably by a constructor, with a state indicating if it can be modified.  The modifier methods would check this state to see if the operation was allowed. &lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      protected boolean mutable;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle(boolean mutable) {&lt;br /&gt;
          this.mutable = mutable;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          if (mutable)&lt;br /&gt;
              this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
     ...&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-Patterns] (Wikipedia)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* Robert C. Martin, [http://www.objectmentor.com/resources/articles/lsp.pdf The Liskov Substitution Principle], C++ Report, March 1996.&lt;br /&gt;
* Jean-Luc Hainaut, Jean-Marc Hick, Vincent Englebert, Jean Henrard, Didier Roland: Understanding Implementations of IS-A Relations. ER 1996: 42-57&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43414</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43414"/>
		<updated>2010-12-11T03:44:57Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern], also known as the [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse problem] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] with inheritance when a base class contains methods which invalidate the derived class, and thereby violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle].&lt;br /&gt;
&lt;br /&gt;
[[Image:Square-rectangle.gif|right|150px]]&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square. By the 'is a' test, one might reasonably define the Square class as a specialization of the Rectangle class (Square is a Rectangle), where all sides are of equal length.  But suppose Rectangle defines a constructor that takes two arguments, x and y, for the lengths of the sides. How can Square provide an implementation for this constructor?  If the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
The situation is worse for modifier methods on the base class. Suppose Rectangle has a method setX which modifies only two sides of the rectangle. When called on a Square, it would cause the object to no longer be a square. This can be particularly problematic when new modifiers are added to an existing base class after it has been subclassed. If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following example illustrates the problem. In this case, Square has decided not to implement a constructor defined in Rectangle. But there is still a problem with the setX modifier:&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void print() {&lt;br /&gt;
          System.out.println(this.getClass().getName() + &amp;quot; has sides of length &amp;quot; + x + &amp;quot; and &amp;quot; + y);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public static void main(String[] args) {&lt;br /&gt;
          Square s = new Square(10);&lt;br /&gt;
          s.print();&lt;br /&gt;
          s.setX(5);&lt;br /&gt;
          s.print();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This produces the following output:&lt;br /&gt;
&lt;br /&gt;
  Square has sides of length 10 and 10&lt;br /&gt;
  Square has sides of length 5 and 10&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
  public class Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int x;&lt;br /&gt;
  &lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  class Rectangle extends Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Hidden constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could choose to not provide an implementation for the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This design maybe controversial since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) { }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) {&lt;br /&gt;
         throw new UnsupportedOperationException();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
In Java the [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/UnsupportedOperationException.html UnsupportedOperationException] could be thrown, which is a [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/RuntimeException.html RuntimeException] and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.[1] The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          super(x, x);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
When a method is called that will mutate the object, the implementation could instantiate an instance of the base class and return that instead[1]. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          super(x, x);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          if (x == this.y)&lt;br /&gt;
              return super(x);&lt;br /&gt;
          else&lt;br /&gt;
              return new Rectangle(x);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Use separate immutable and mutable classes ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the Rectangle class is [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore its methods cannot change derived instances, they can only return new instances of Rectangle.  A separate MutableRectangle class could be defined and all the modifiers put into it.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  class ImmutableRectangle extends Rectangle&lt;br /&gt;
  {&lt;br /&gt;
      public Rectangle() { super(); }&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          super(x, y);&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private void setX(int x) { }&lt;br /&gt;
  &lt;br /&gt;
      private void setY(int y) { }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends ImmutableRectangle &lt;br /&gt;
  {&lt;br /&gt;
      ...&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
=== Initialize base class as mutable/immutable ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the above but not requiring separate mutable and immutable classes. Rectangle could be initialized, presumably by a constructor, with a state indicating if it can be modified.  The modifier methods would check this state to see if the operation was allowed. &lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      protected boolean mutable;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle(boolean mutable) {&lt;br /&gt;
          this.mutable = mutable;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          if (mutable)&lt;br /&gt;
              this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
     ...&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-Patterns] (Wikipedia)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* Robert C. Martin, [http://www.objectmentor.com/resources/articles/lsp.pdf The Liskov Substitution Principle], C++ Report, March 1996.&lt;br /&gt;
* Jean-Luc Hainaut, Jean-Marc Hick, Vincent Englebert, Jean Henrard, Didier Roland: Understanding Implementations of IS-A Relations. ER 1996: 42-57&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43413</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43413"/>
		<updated>2010-12-11T03:32:25Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern], also known as the [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse problem] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] with inheritance when a base class contains methods which invalidate the derived class, and thereby violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle].&lt;br /&gt;
&lt;br /&gt;
[[Image:Square-rectangle.gif|right|150px]]&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square. By the 'is a' test, one might reasonably define the Square class as a specialization of the Rectangle class (Square is a Rectangle), where all sides are of equal length.  But suppose Rectangle defines a constructor that takes two arguments, x and y, for the lengths of the sides. How can Square provide an implementation for this constructor?  If the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
The situation is worse for modifier methods on the base class. Suppose Rectangle has a method setX which modifies only two sides of the rectangle. When called on a Square, it would cause the object to no longer be a square. This can be particularly problematic when new modifiers are added to an existing base class after it has been subclassed. If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following example illustrates the problem. In this case, Square has decided not to implement a constructor defined in Rectangle. But there is still a problem with the setX modifier:&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public void print() {&lt;br /&gt;
          System.out.println(this.getClass().getName() + &amp;quot; has sides of length &amp;quot; + x + &amp;quot; and &amp;quot; + y);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public static void main(String[] args) {&lt;br /&gt;
          Square s = new Square(10);&lt;br /&gt;
          s.print();&lt;br /&gt;
          s.setX(5);&lt;br /&gt;
          s.print();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This produces the following output:&lt;br /&gt;
&lt;br /&gt;
  Square has sides of length 10 and 10&lt;br /&gt;
  Square has sides of length 5 and 10&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
  public class Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int x;&lt;br /&gt;
  &lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  class Rectangle extends Square&lt;br /&gt;
  {&lt;br /&gt;
      protected int y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setY(int y) {&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Hidden constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could choose to not provide an implementation for the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This design maybe controversial since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) { }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      public Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      private Square(int x, int y) {&lt;br /&gt;
         throw new UnsupportedOperationException();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
In Java the [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/UnsupportedOperationException.html UnsupportedOperationException] could be thrown, which is a [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/RuntimeException.html RuntimeException] and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.[1] The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected int setX(int x) {&lt;br /&gt;
          return this.x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected void setX(int x) {&lt;br /&gt;
          super(x);&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
When a method is called that will mutate the object, the implementation could instantiate an instance of the base class and return that instead[1]. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      public Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          return this;&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      public Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      protected Rectangle setX(int x) {&lt;br /&gt;
          if (x == this.y)&lt;br /&gt;
              return super(x);&lt;br /&gt;
          else&lt;br /&gt;
              return new Rectangle(x);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Use separate immutable and mutable classes ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the Rectangle class is [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore its methods cannot change derived instances, they can only return new instances of Rectangle.  A separate MutableRectangle class could be defined and all the modifiers put into it.&lt;br /&gt;
&lt;br /&gt;
As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
=== Initialize base class as mutable/immutable ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the above but not requiring separate mutable and immutable classes. Rectangle could be initialized, presumably by a constructor, with a state indicating if it can be modified.  The modifier methods would check this state to see if the operation was allowed. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-Patterns] (Wikipedia)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* Robert C. Martin, [http://www.objectmentor.com/resources/articles/lsp.pdf The Liskov Substitution Principle], C++ Report, March 1996.&lt;br /&gt;
* Jean-Luc Hainaut, Jean-Marc Hick, Vincent Englebert, Jean Henrard, Didier Roland: Understanding Implementations of IS-A Relations. ER 1996: 42-57&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43011</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43011"/>
		<updated>2010-12-01T15:35:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern], also known as the [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse problem] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] with inheritance when a base class contains methods which invalidate the derived class, and thereby violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle].&lt;br /&gt;
&lt;br /&gt;
[[Image:Square-rectangle.gif|right|150px]]&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square. By the 'is a' test, one might reasonably define the Square class as a specialization of the Rectangle class (Square is a Rectangle), where all sides are of equal length.  But suppose Rectangle defines a constructor that takes two arguments, x and y, for the lengths of the sides. How can Square provide an implementation for this constructor?  If the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
The situation is worse for modifier methods on the base class. Suppose Rectangle has a method setX which modifies only two sides of the rectangle. When called on a Square, it would cause the object to no longer be a square. This can be particularly problematic when new modifiers are added to an existing base class after it has been subclassed. If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following example illustrates the problem. In this case, Square has decided not to implement a constructor defined in Rectangle. But there is still a problem with the setX modifier:&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      void print() {&lt;br /&gt;
          System.out.println(this.getClass().getName() + &amp;quot; has sides of length &amp;quot; + x + &amp;quot; and &amp;quot; + y);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public static void main(String[] args) {&lt;br /&gt;
          Square s = new Square(10);&lt;br /&gt;
          s.print();&lt;br /&gt;
          s.setX(5);&lt;br /&gt;
          s.print();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This produces the following output:&lt;br /&gt;
&lt;br /&gt;
  Square has sides of length 10 and 10&lt;br /&gt;
  Square has sides of length 5 and 10&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Absent constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could choose to not provide an implementation for the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This design maybe controversial since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
In Java the [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/UnsupportedOperationException.html UnsupportedOperationException] could be thrown, which is a [http://download.oracle.com/javase/1.5.0/docs/api/java/lang/RuntimeException.html RuntimeException] and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.  The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
If the constructor is called with different values for x and y, or if the setx method is called, the implementation on Square could instantiate an instance of Rectangle and return that instead. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
=== Use separate immutable and mutable classes ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the Rectangle class is [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore its methods cannot change derived instances, they can only return new instances of Rectangle.  A separate MutableRectangle class could be defined and all the modifiers put into it.&lt;br /&gt;
&lt;br /&gt;
As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
=== Initialize base class as mutable/immutable ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the above but not requiring separate mutable and immutable classes. Rectangle could be initialized, presumably by a constructor, with a state indicating if it can be modified.  The modifier methods would check this state to see if the operation was allowed. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-Patterns] (Wikipedia)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* Robert C. Martin, [http://www.objectmentor.com/resources/articles/lsp.pdf The Liskov Substitution Principle], C++ Report, March 1996.&lt;br /&gt;
* Jean-Luc Hainaut, Jean-Marc Hick, Vincent Englebert, Jean Henrard, Didier Roland: Understanding Implementations of IS-A Relations. ER 1996: 42-57&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Square-rectangle.gif&amp;diff=43010</id>
		<title>File:Square-rectangle.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Square-rectangle.gif&amp;diff=43010"/>
		<updated>2010-12-01T15:10:12Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43009</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=43009"/>
		<updated>2010-12-01T14:48:20Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] with inheritance when a base class contains methods which invalidate the derived class, and thereby violate the [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle].&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square. By the [http://en.wikipedia.org/wiki/Is-a 'is a'] test, one might reasonably define the Square class as a specialization of the Rectangle class (Square is a Rectangle), where all sides are of equal length.  But suppose Rectangle defines a constructor that takes two arguments, x and y, for the lengths of the sides. How can Square provide an implementation for this constructor?  If the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
The situation is worse for modifier methods on the base class. Suppose Rectangle has a method setX which modifies only two sides of the rectangle. When called on a Square, it would cause the object to no longer be a square. This can be particularly problematic when new modifiers are added to an existing base class after it has been subclassed. If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following example illustrates the problem. In this case, Square has decided not to implement a constructor defined in Rectangle. But there is still a problem with the setX modifier:&lt;br /&gt;
&lt;br /&gt;
  class Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      protected int x, y;&lt;br /&gt;
  &lt;br /&gt;
      Rectangle() {}&lt;br /&gt;
    &lt;br /&gt;
      Rectangle(int x, int y) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = y;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      void setX(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      void print() {&lt;br /&gt;
          System.out.println(this.getClass().getName() + &amp;quot; has sides of length &amp;quot; + x + &amp;quot; and &amp;quot; + y);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  public class Square extends Rectangle &lt;br /&gt;
  {&lt;br /&gt;
      Square(int x) {&lt;br /&gt;
          this.x = x;&lt;br /&gt;
          this.y = x;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      public static void main(String[] args) {&lt;br /&gt;
          Square s = new Square(10);&lt;br /&gt;
          s.print();&lt;br /&gt;
          s.setX(5);&lt;br /&gt;
          s.print();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This produces the following output:&lt;br /&gt;
&lt;br /&gt;
  Square has sides of length 10 and 10&lt;br /&gt;
  Square has sides of length 5 and 10&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Absent constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could choose to not provide an implementation for the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This design maybe controversial since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
In Java the UnsupportedOperationException could be thrown, which is a RuntimeException and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.  The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
If the constructor is called with different values for x and y, or if the setx method is called, the implementation on Square could instantiate an instance of Rectangle and return that instead. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
=== Use separate immutable and mutable classes ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the Rectangle class is [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore its methods cannot change derived instances, they can only return new instances of Rectangle.  A separate MutableRectangle class could be defined and all the modifiers put into it.&lt;br /&gt;
&lt;br /&gt;
As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
=== Initialize base class as mutable/immutable ===&lt;br /&gt;
&lt;br /&gt;
This is similar to the above but not requiring separate mutable and immutable classes. Rectangle could be initialized, presumably by a constructor, with a state indicating if it can be modified.  The modifier methods would check this state to see if the operation was allowed. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Circle-ellipse_problem Circle-Ellipse Problem] (Wikipedia)&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Liskov_substitution_principle Liskov Substitution Principle] (Wikipedia)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=42852</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=42852"/>
		<updated>2010-11-30T03:25:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square-Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square-Rectangle [http://en.wikipedia.org/wiki/Anti-pattern Anti-Pattern] is a software development problem that can occur in [http://en.wikipedia.org/wiki/Object_oriented_programming Object Oriented Programming] when using inheritance.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square.  One might reasonably define the Square class as a specific type of the Rectangle class since it passes the 'is a' test (Square is a Rectangle).  This leads to several problems however, since subclasses are supposed to support all the methods of their super class.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
Conceptually this problem happens when the base class contains more information than the derived class. In the example of the Square and the Rectangle, both have two sides x and y, but in the case of a Rectangle the sides may be of different length and therefore two values must be maintained.&lt;br /&gt;
&lt;br /&gt;
Within the code the base class Rectangle may have a constructor that accepts two parameters, x and y, to set the length of its sides.  How is the Square class to implement this constructor? It could override the constructor but if the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
=== Mutating Methods ===&lt;br /&gt;
&lt;br /&gt;
The situation is likewise for mutating methods, which modif an object which was already instantiated. For example the Rectangle class may have a method setX which modifies the size of only one side of the rectangle.  When called on a Square, it would cause the object to no longer be a square.  &lt;br /&gt;
&lt;br /&gt;
This becomes particularly problematic when new methods are added to an existing base class after it has been subclassed.  If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Absent constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could just choose not to implement the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This is confusing though, since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
=== Throw exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
In Java the UnsupportedOperationException could be thrown, which is a RuntimeException and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.  The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
=== Return instance of new class ===&lt;br /&gt;
&lt;br /&gt;
If the constructor is called with different values for x and y, or if the setx method is called, the implementation on Square could instantiate an instance of Rectangle and return that instead. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
=== Make all classes immutable ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the classes are [http://en.wikipedia.org/wiki/Immutable_object immutable] and therefore the methods cannot change the existing class, they can only return new instances of the proper class. As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=42851</id>
		<title>CSC/ECE 517 Fall 2010/ch7 7g mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch7_7g_mr&amp;diff=42851"/>
		<updated>2010-11-30T02:39:04Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Square Rectangle Anti-Pattern =&lt;br /&gt;
&lt;br /&gt;
The Square Rectangle Anti-Pattern is a software development problem that can occur specifically in Object Oriented Programming when subclassing.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
Consider classes Rectangle and Square.  One might reasonably define the Square class as a specific type of the Rectangle class since it passes the 'is a' test (Square is a Rectangle).  This leads to several problems however, since subclasses are supposed to support all the methods of their super class.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Constructor ===&lt;br /&gt;
&lt;br /&gt;
Conceptually this problem happens when the base class contains more information than the derived class. In the example of the Square and the Rectangle, both have two sides x and y, but in the case of a Rectangle the sides may be of different length and therefore two values must be maintained.&lt;br /&gt;
&lt;br /&gt;
Within the code the base class Rectangle may have a constructor that accepts two parameters, x and y, to set the length of its sides.  How is the Square class to implement this constructor? It could override the constructor but if the values passed for x and y are not the same, it would be unable to construct an instance of Square that satisfied the input criteria.&lt;br /&gt;
&lt;br /&gt;
=== Mutating Methods ===&lt;br /&gt;
&lt;br /&gt;
The situation is likewise for mutating methods, which modif an object which was already instantiated. For example the Rectangle class may have a method setX which modifies the size of only one side of the rectangle.  When called on a Square, it would cause the object to no longer be a square.  &lt;br /&gt;
&lt;br /&gt;
This becomes particularly problematic when new methods are added to an existing base class after it has been subclassed.  If it has been subclassed improperly, the subclasses may be broken by the new functionality in the base class.&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
&lt;br /&gt;
=== Reverse the inheritance ===&lt;br /&gt;
&lt;br /&gt;
Instead of having Square be a subclass of Rectangle, one could make Rectangle a subclass of Square. Afterall, you could say a Rectangle is a specialization of Square in which the sides don't need to be of the same length.  Thus Square would define a constructor that takes only argument x.  Rectangle could support that constructor and also provide another constructor which takes x and y.  Likewise, Square could have only a setx method whereas Rectangle could also define a sety method.&lt;br /&gt;
&lt;br /&gt;
This is somewhat of a contrived example since Square does not have any additional information than Rectangle. Such may not be the case in more realistic scenarios.&lt;br /&gt;
&lt;br /&gt;
=== Absent Constructor ===&lt;br /&gt;
&lt;br /&gt;
The derived Rectangle class could just choose not to implement the constructor that takes arguments x and y.  This would prevent any caller from instantiating an instance of Square with arguments x and y.  This is confusing though, since one normally expects a subclass to support all the constructors of the base class.&lt;br /&gt;
&lt;br /&gt;
=== Throw Exception ===&lt;br /&gt;
&lt;br /&gt;
The Square class could override any methods or constructors which violate the contract and throw an exception.  In the constructor example above, it could throw an exception if the lengths provided for x and y are not equal.  In the setx method example, it could check the value of y and throw an exception if the passed in value for x wasn't equal to y. This is somewhat dubious but does allow the setx method to be called if the value isn't changing.&lt;br /&gt;
&lt;br /&gt;
In Java the UnsupportedOperationException could be thrown, which is a RuntimeException and therefore does not need to be declared. If another type of exception was thrown, it would have to be declared.&lt;br /&gt;
&lt;br /&gt;
=== Return new value ===&lt;br /&gt;
&lt;br /&gt;
In this solution, the super class method would need to return its new value X when a method is called to change it.  The derived class reacts by stubbornly just returning its current value, thus forcing the caller to use a method supported for that class.  This solution avoids throwing exceptions but could have undesireable consequences if the calling code is not careful to check the return value to make sure it was modified.  But perhaps worse, it requires the method signatures to be changed in the base class to support the problem in the derived class.&lt;br /&gt;
&lt;br /&gt;
=== Make method more powerful ===&lt;br /&gt;
&lt;br /&gt;
The implementation for the setx method in Square could just change the value of y also. This results in the method becoming more powerful, and might not be what the caller intended. &lt;br /&gt;
&lt;br /&gt;
=== Convert Square to Rectangle ===&lt;br /&gt;
&lt;br /&gt;
If the constructor is called with different values for x and y, or if the setx method is called, the implementation on Square could instantiate an instance of Rectangle and return that instead. This requires the methods to declare a return type of the base class.  This could have unexpected consequences on the program.&lt;br /&gt;
&lt;br /&gt;
=== Make all classes immutable ===&lt;br /&gt;
&lt;br /&gt;
In this approach, the classes are immutable and therefore the methods cannot change the existing class, they can only return new instances of the proper class. As in some of the previous solutions, this has the disadvantage of requiring significant modifications to the design of the base class.  It also requires the calling code to perform more assignments and may result in more memory being consumed by all the immutable instances around. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37879</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37879"/>
		<updated>2010-10-13T15:50:27Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] (AOP) for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to and shares terminology with the  [http://en.wikipedia.org/wiki/AspectJ AspectJ] library for Java.&lt;br /&gt;
&lt;br /&gt;
AspectR was developed by Avi Bryant and Robert Feldt; it is distributed under the GNU General Public License [1].&lt;br /&gt;
&lt;br /&gt;
== Overview of AOP ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing code that ''cross-cuts'' the core components or business logic of a program [2]. Logging is a classical example of a ''concern'' which cross-cuts the core components of a program, and thus violates the widely held principle on Separation of Concerns. AOP solves this problem and is complimentary to Object Oriented Programming because it allows the concerns which cuts across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [3]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  &lt;br /&gt;
&lt;br /&gt;
Unlike AspectJ, however, AspectR does not require a separate language processor to coordinate the composition of program from the aspects and the business logic code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
# Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
# AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Separation_of_concerns Separation of Concerns on Wikipedia]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37878</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37878"/>
		<updated>2010-10-13T15:47:38Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] (AOP) for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to and shares terminology with the  [http://en.wikipedia.org/wiki/AspectJ AspectJ] library for Java.&lt;br /&gt;
&lt;br /&gt;
AspectR was developed by Avi Bryant and Robert Feldt; it is distributed under the GNU General Public License [1].&lt;br /&gt;
&lt;br /&gt;
== Overview of AOP ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing code that ''cross-cuts'' the core components or business logic of a program [2]. Logging is a classical example of a ''concern'' which cross-cuts the core components of a program, and thus violates the widely held principle on Separation of Concerns. AOP solves this problem and is complimentary to Object Oriented Programming because it allows the concerns which cuts across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [3]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  &lt;br /&gt;
&lt;br /&gt;
Unlike AspectJ, however, AspectR does not require a separate language processor to coordinate the composition of program from the aspects and the business logic code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
# Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
# AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37823</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37823"/>
		<updated>2010-10-11T19:47:26Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] (AOP) for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to and shares terminology with the  [http://en.wikipedia.org/wiki/AspectJ AspectJ] library for Java.&lt;br /&gt;
&lt;br /&gt;
AspectR was developed by Avi Bryant and Robert Feldt; it is distributed under the GNU General Public License [1].&lt;br /&gt;
&lt;br /&gt;
== Overview of AOP ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic of a program [2]. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [3]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
# Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
# AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37822</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37822"/>
		<updated>2010-10-11T19:45:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to and shares terminology with the  [http://en.wikipedia.org/wiki/AspectJ AspectJ] library for Java.&lt;br /&gt;
&lt;br /&gt;
AspectR was developed by Avi Bryant and Robert Feldt; it is distributed under the GNU General Public License [1].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program [2]. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [3]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
# Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
# AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37821</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37821"/>
		<updated>2010-10-11T19:44:53Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to and shares terminology with the  [http://en.wikipedia.org/wiki/AspectJ AspectJ] library for Java.&lt;br /&gt;
&lt;br /&gt;
AspectR was developed by Avi Bryant and Robert Feldt; it is distributed under the GNU General Public License [1].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program [2]. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [3]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
3. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37820</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37820"/>
		<updated>2010-10-11T19:39:51Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37819</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37819"/>
		<updated>2010-10-11T19:39:16Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Motivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
Consider the following exercise...&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37818</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37818"/>
		<updated>2010-10-11T19:38:50Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Motivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
: 1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
: 2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
: 3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
: 4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37817</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37817"/>
		<updated>2010-10-11T19:36:29Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Motivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
# Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
## Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
### Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
#### Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37816</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37816"/>
		<updated>2010-10-11T19:36:05Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Motivation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
# Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
# Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
# Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
# Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37815</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37815"/>
		<updated>2010-10-11T19:31:21Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
'''AspectR''' is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming] for Ruby programs by providing ways to wrap code around existing methods in a program. Similar to the AspectJ library for Java, AspectR was developed by Avi Bryant and Robert Feldt [1], and distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
1 Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
1 Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
1 Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
1 Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [2]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
Unlike AspectR, the aspects in AspectJ programs must be transformed into valid Java code.  &lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR README. http://aspectr.sourceforge.net/ January 29, 2002&lt;br /&gt;
2. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
3. Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). &amp;quot;Aspect-Oriented Programming&amp;quot;. Proceedings of the European Conference on Object-Oriented Programming, vol.1241. pp. 220–242.&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://ruby-doc.org/ Ruby Documentation]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37814</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37814"/>
		<updated>2010-10-11T18:11:44Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is similar in functionality to the AspectJ library for Java, except simpler, less well known, and less documented. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming (AOP) is an approach to modularizing concerns that cut across the core concerns or business logic of a program. AOP is complimentary to Object Oriented Programming because it allows those concerns which cut across the program to be encapsulated into their own classes, called aspects.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
1. Take a shopping cart application with a Cart class and method add_to_cart():&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     items &amp;lt;&amp;lt; item&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This code is easy to understand and maintain.  &lt;br /&gt;
&lt;br /&gt;
2. Now add security, database transactions, and logging code:&lt;br /&gt;
&lt;br /&gt;
 class Cart&lt;br /&gt;
   has_many :items&lt;br /&gt;
   def add_to_cart(item)&lt;br /&gt;
     log('entering method')&lt;br /&gt;
     check_permissions&lt;br /&gt;
     conn = new_connection&lt;br /&gt;
     begin&lt;br /&gt;
       items &amp;lt;&amp;lt; item&lt;br /&gt;
     rescue&lt;br /&gt;
       log('exception')&lt;br /&gt;
     ensure&lt;br /&gt;
       conn.close&lt;br /&gt;
     end&lt;br /&gt;
     log('leaving method')     &lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
3. Make the same changes to other business logic methods throughout the program.&lt;br /&gt;
&lt;br /&gt;
4. Finally, try reusing this code in another application which has a different transaction framework, uses a different logging library, or handles security differently.&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming resolves this problem by encapsulating the concerns that cut across the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
AspectR uses a lot of the same terminology as AspectJ. &lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Although the library is quite small, AspectR is a useful tool for implementing Aspect-Oriented Programming in Ruby programs. The main limitation of the library is that it only supports wrapping methods with join points either before or after the method calls. More complex join points are not supported at the time of this writing.  Unlike AspectJ, however, AspectR conveniently does not require an intermediate step to generate the Java source code from the AspectJ code.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Model_view_controller]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37813</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37813"/>
		<updated>2010-10-11T17:26:53Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Aspect-Oriented Programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
[[Image:Aop.GIF]]&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Aop.GIF&amp;diff=37812</id>
		<title>File:Aop.GIF</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Aop.GIF&amp;diff=37812"/>
		<updated>2010-10-11T17:25:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37792</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37792"/>
		<updated>2010-10-08T11:50:05Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* AspectR */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37791</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37791"/>
		<updated>2010-10-08T11:49:58Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* AspectR */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 The following code defines a class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; and tests the aspect:&lt;br /&gt;
&lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37790</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37790"/>
		<updated>2010-10-08T11:48:51Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 &lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
 &lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
 &lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37789</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37789"/>
		<updated>2010-10-08T11:47:59Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
 import java.util.Date;&lt;br /&gt;
&lt;br /&gt;
 aspect Profiler {&lt;br /&gt;
   private Date beginTime;&lt;br /&gt;
   &lt;br /&gt;
   pointcut myMethod(SomeClass s): target(s) &amp;amp;&amp;amp; call(public * some*(..));&lt;br /&gt;
&lt;br /&gt;
   before(SomeClass s): myMethod(s) {&lt;br /&gt;
     this.beginTime = new Date();&lt;br /&gt;
   }&lt;br /&gt;
   after(SomeClass s): myMethod(s) {&lt;br /&gt;
     Date newTime = new Date();&lt;br /&gt;
     int timeElapsed = this.beginTime.getTime() - newTime.getTime();&lt;br /&gt;
     System.out.println(thisJoinPointStaticPart + &amp;quot; took &amp;quot; + timeElapsed + &amp;quot; secs&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37040</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37040"/>
		<updated>2010-10-06T13:23:32Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change [1]:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
1. AspectR Ruby documentation (RDoc), AspectR module&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37037</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37037"/>
		<updated>2010-10-06T13:22:35Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&amp;lt;ref&amp;gt;&amp;quot;Adaptive Object Oriented Programming: The Demeter Approach with Propagation Patterns&amp;quot; ''Karl Liebherr'' 1996 ISBN 0-534-94602-X presents a well-worked version of essentially the same thing (Lieberherr subsequently recognized this and reframed his approach).&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change &amp;lt;ref&amp;gt;AspectR Ruby documentation (RDoc), AspectR module&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37036</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37036"/>
		<updated>2010-10-06T13:21:59Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change &amp;lt;ref&amp;gt;AspectR Ruby documentation (RDoc), AspectR module&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37035</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37035"/>
		<updated>2010-10-06T13:18:23Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change &amp;lt;ref&amp;gt;[[Edsger, Feldt]], AspectR Ruby documentation, AspectR module&amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37031</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37031"/>
		<updated>2010-10-06T13:12:21Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables Aspect-oriented programming for Ruby programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the AspectJ library for Java, but less well known. AspectR is distributed under the GNU General Public License.&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-Oriented Programming on Wikipedia]&lt;br /&gt;
* [http://aspectr.sourceforge.net/ AspectR home page]&lt;br /&gt;
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide]&lt;br /&gt;
* [http://ruby-doc.org/docs/ProgrammingRuby/html/ Programming Ruby - The Pragmatic Programmer's Guide]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/GPL GNU Public License]&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37028</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37028"/>
		<updated>2010-10-06T13:03:40Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-oriented programming] for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the [http://en.wikipedia.org/wiki/Aspectj AspectJ] library for Java, but less well known. AspectR is distributed under the [http://en.wikipedia.org/wiki/GPL GNU General Public License].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
Code can be executed with dispatching by the API disabled using the &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; instance method on the aspect class. Although temporary, the effect is global to the API. For example the following code will NOT result in the advice methods being called:&lt;br /&gt;
&lt;br /&gt;
  profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
  profiler.disable_advice_dispatching { SomeClass.new.some_method }&lt;br /&gt;
&lt;br /&gt;
One can test to see if the API dispatching is disabled using the Aspect class method &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt;, for example:&lt;br /&gt;
&lt;br /&gt;
 Aspect.dispatch?&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37024</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37024"/>
		<updated>2010-10-06T12:48:39Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-oriented programming] for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the [http://en.wikipedia.org/wiki/Aspectj AspectJ] library for Java, but less well known. AspectR is distributed under the [http://en.wikipedia.org/wiki/GPL GNU General Public License].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
 def method_start(method, object, exitstatus, *args)&lt;br /&gt;
   @begin = Time.now&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 def method_end(method, object, exitstatus, *args)&lt;br /&gt;
   timeElapsed = Time.now - @begin&lt;br /&gt;
   puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given the simple example,&lt;br /&gt;
&lt;br /&gt;
 class SomeClass&lt;br /&gt;
   def some_method&lt;br /&gt;
     puts &amp;quot;hello&amp;quot;&lt;br /&gt;
     sleep 5&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method using the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method, for example:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new&lt;br /&gt;
 &lt;br /&gt;
 profiler.add_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.add_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 profiler.remove_advice(SomeClass, :PRE, :some_method, :method_start)&lt;br /&gt;
 profiler.remove_advice(SomeClass, :POST, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
We can wrap both the before and after join points, and specify multiple target methods, for example the following code will wrap all the methods from the class &amp;lt;code&amp;gt;SomeClass&amp;lt;/code&amp;gt; which match the regular expression &amp;quot;/some/&amp;quot; with our advice methods for the before and after join points:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Similarly, this can be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.unwrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can have code directly injected into the beginning and ending of the target methods . This has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 profiler.wrap_with_code(SomeClass, '@begin = Time.now', 'timeElapsed = Time.now - @begin; puts &amp;quot;took #{timeElapsed} secs&amp;quot;' , /some/)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a  &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes(profiler, :method_start, :method_end, /Some/, /some/)&lt;br /&gt;
&lt;br /&gt;
One can specify that one or more methods which should never be wrapped by passing in the beginning of the method name to the constructor. There is also a &amp;lt;code&amp;gt;wrappable?&amp;lt;/code&amp;gt; method to test if a method can be wrapped. For example this code will result in the wrap being ignored and return true:&lt;br /&gt;
&lt;br /&gt;
 profiler = Profiler.new(&amp;quot;some&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
 &lt;br /&gt;
 profiler.wrappable?(:some_method)&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37015</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37015"/>
		<updated>2010-10-06T11:51:31Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-oriented programming] for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the [http://en.wikipedia.org/wiki/Aspectj AspectJ] library for Java, but less well known. AspectR is distributed under the [http://en.wikipedia.org/wiki/GPL GNU General Public License].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Borrowed from AspectJ terminology, refers to Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class. For example, we define a new aspect class to implement a code profiler:&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. &lt;br /&gt;
&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   &lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
   profiler = Profiler.new&lt;br /&gt;
&lt;br /&gt;
AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. Given the simple example,&lt;br /&gt;
&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
One can add advice to be invoked before or after a single target method as follows:&lt;br /&gt;
&lt;br /&gt;
   profiler.add_advice(SomeClass, :PRE, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
This advice can be removed using &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
   profiler.remove_advice(SomeClass, :PRE, :some_method, :method_end)&lt;br /&gt;
&lt;br /&gt;
:The AspectR API provides the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method to add an advice method to be invoked before or after a single target method.&lt;br /&gt;
&lt;br /&gt;
To add an advice method to be invoked before or after a single target method, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 add_advice (target, joinpoint, method, advice)&lt;br /&gt;
 &lt;br /&gt;
 remove_advice (target, joinpoint, method, advice)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
** &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
** &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
** &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 wrap (target, pre, post, *args)&lt;br /&gt;
 &lt;br /&gt;
 unwrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 wrap_with_code (target, preCode, postCode, *args)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes (aspect, pre, post, classes, *methods)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37014</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37014"/>
		<updated>2010-10-06T11:30:59Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-oriented programming] for [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the [http://en.wikipedia.org/wiki/Aspectj AspectJ] library for Java, but less well known. AspectR is distributed under the [http://en.wikipedia.org/wiki/GPL GNU General Public License].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
==== Motivation ====&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== The AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping ===&lt;br /&gt;
&lt;br /&gt;
To add an advice method to be invoked before or after a single target method, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 add_advice (target, joinpoint, method, advice)&lt;br /&gt;
 &lt;br /&gt;
 remove_advice (target, joinpoint, method, advice)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
** &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
** &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
** &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 wrap (target, pre, post, *args)&lt;br /&gt;
 &lt;br /&gt;
 unwrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 wrap_with_code (target, preCode, postCode, *args)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes (aspect, pre, post, classes, *methods)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37013</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=37013"/>
		<updated>2010-10-06T11:27:22Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a programming library that enables [http://en.wikipedia.org/wiki/Aspect-oriented_programming Aspect-oriented programming] [http://en.wikipedia.org/wiki/Ruby_%28programming_language%29 Ruby] programs by providing ways to wrap code around existing methods in a program. It is simpler but similar in functionality to the [http://en.wikipedia.org/wiki/Aspectj AspectJ] library for Java, but less well known. AspectR is distributed under the [http://en.wikipedia.org/wiki/GPL GNU General Public License].&lt;br /&gt;
&lt;br /&gt;
== Aspect-Oriented Programming ==&lt;br /&gt;
&lt;br /&gt;
Aspect-Oriented Programming is an approach to modularizing concerns that cut across the core concerns or business logic, of a program.&lt;br /&gt;
&lt;br /&gt;
=== Motivation ===&lt;br /&gt;
&lt;br /&gt;
The model code in a typical program will often contain not only the business logic but also secondary concerns such as transactions, security, logging, etc.  This clutters the code in the model, making it hard to distinguish the business logic from the secondary code, complicating maintenance and reuse. Furthermore, these secondary concerns cut across multiple core concerns in the program, which violates the separation of concerns. As a result, changing to a different transaction API, for example, results in code modifications throughout the program.&lt;br /&gt;
&lt;br /&gt;
=== Terminology ===&lt;br /&gt;
&lt;br /&gt;
* Aspects - Classes that implement functionality needed in many parts of a program, but are not part of the business logic or core concern of the program.&lt;br /&gt;
&lt;br /&gt;
* Advice - Aspect methods or code to be applied around existing business logic.&lt;br /&gt;
&lt;br /&gt;
* Join Point - Places in the core business logic that advice should be applied or wrapped around.&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping ===&lt;br /&gt;
&lt;br /&gt;
To add an advice method to be invoked before or after a single target method, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 add_advice (target, joinpoint, method, advice)&lt;br /&gt;
 &lt;br /&gt;
 remove_advice (target, joinpoint, method, advice)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 wrap (target, pre, post, *args)&lt;br /&gt;
 &lt;br /&gt;
 unwrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 wrap_with_code (target, preCode, postCode, *args)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes (aspect, pre, post, classes, *methods)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36783</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36783"/>
		<updated>2010-10-05T15:36:05Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To add an advice method to be invoked before or after a single target method, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 add_advice (target, joinpoint, method, advice)&lt;br /&gt;
 &lt;br /&gt;
 remove_advice (target, joinpoint, method, advice)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 wrap (target, pre, post, *args)&lt;br /&gt;
 &lt;br /&gt;
 unwrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
 wrap_with_code (target, preCode, postCode, *args)&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
 wrap_classes (aspect, pre, post, classes, *methods)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36782</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36782"/>
		<updated>2010-10-05T15:35:31Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To add an advice method to be invoked before or after a single target method, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 add_advice (target, joinpoint, method, advice)&lt;br /&gt;
 &lt;br /&gt;
 remove_advice (target, joinpoint, method, advice)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
 wrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
 unwrap (target, pre, post, *args)&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36781</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36781"/>
		<updated>2010-10-05T15:31:41Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To wrap only one join point (before or after method invocation) for a single method in a target class to an advice method in the aspect class, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wrap target methods to blocks of advice code using the &amp;lt;code&amp;gt;wrap_with_code&amp;lt;/code&amp;gt; instance method. Has performance advantages but cannot be unwrapped:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To wrap methods from multiple target classes, the AspectR library defines a global &amp;lt;code&amp;gt;wrap_classes&amp;lt;/code&amp;gt; method. This is an experimental method and the API is likely to change:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;aspect&amp;lt;/code&amp;gt; - aspect class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;classes&amp;lt;/code&amp;gt; - regular expression to match target class names&lt;br /&gt;
* &amp;lt;code&amp;gt;*methods&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target classes&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36780</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36780"/>
		<updated>2010-10-05T15:23:30Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To wrap only one join point (before or after method invocation) for a single method in a target class to an advice method in the aspect class, use the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove_advice&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
To wrap both the before and after join points, and specify multiple target methods, use the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt; instance methods on the Aspect class:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - advice method to call before target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - advice method to call after target method invocations&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - target methods, or regular expression matching method names in the target class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36779</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36779"/>
		<updated>2010-10-05T15:18:37Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To wrap only one join point (before or after method invocation) for a single method in a target class to an advice method in the aspect class, use the following methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Parameters:&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - target class&lt;br /&gt;
* &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; - must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; - target method&lt;br /&gt;
* &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; - advice method in the aspect class&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Instance method of the aspect class which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36778</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36778"/>
		<updated>2010-10-05T15:16:00Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for wrapping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
To wrap only one join point (before or after method invocation) for a single method in a target class to an advice method in the aspect class, use the following methods:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; class, &amp;lt;code&amp;gt;joinpoint&amp;lt;/code&amp;gt; must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;method&amp;lt;/code&amp;gt; in the target class, &amp;lt;code&amp;gt;advice&amp;lt;/code&amp;gt; method in the aspect class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Instance method of the aspect class which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36777</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36777"/>
		<updated>2010-10-05T15:01:27Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Specifying methods that should never be wrapped */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Instance method of the aspect class which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - Class method to create a new instance of the aspect class and specify methods that should never be wrapped.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36776</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36776"/>
		<updated>2010-10-05T14:58:55Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods for controlling dispatching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Instance method of the aspect class which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on an instance of the aspect class (any instance).&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Indicates if dispatching to advice methods is enabled.&lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36775</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36775"/>
		<updated>2010-10-05T14:57:17Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods for wrapping  ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Instance method of the aspect class which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== Methods for controlling dispatching ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching to advice methods by the API. Provided as an instance method so must be called on [any] aspect instance&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Returns true if dispatching to advice methods is enabled, false if disabled. &lt;br /&gt;
&lt;br /&gt;
=== Specifying methods that should never be wrapped ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
=== Other utility methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are used by the API itself but also made public:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36774</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36774"/>
		<updated>2010-10-05T14:46:07Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR API ==&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following instance methods are inherited from the Aspect class.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - This is the main utility method which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_with_code (target, preCode, postCode, *args) &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrappable? (method)&amp;lt;/code&amp;gt; - Indicates if the specified method can be wrapped. See [new] below.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching of advice methods in the program.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;get_methods (targret, args)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;prepare (target)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following class methods are inherited from the Aspect class:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Returns true if dispatching to advice methods is enabled, false if disabled. &lt;br /&gt;
&lt;br /&gt;
The following utility methods are provided by the AspectR library:&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The following code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36773</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36773"/>
		<updated>2010-10-05T14:42:18Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Defining Aspects and wrapping methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR ==&lt;br /&gt;
&lt;br /&gt;
=== Defining Aspects and wrapping methods ===&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following instance methods are inherited from the Aspect class.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - This is the main utility method which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching of advice methods in the program.&lt;br /&gt;
&lt;br /&gt;
* get_methods (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* prepare (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrap_with_code (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrappable? (AspectR::Aspect)&lt;br /&gt;
&lt;br /&gt;
The following class methods are inherited from the Aspect class:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Returns true if dispatching to advice methods is enabled, false if disabled. &lt;br /&gt;
&lt;br /&gt;
The following utility methods are provided by the AspectR library:&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wraps methods in one or more classes whose class name matches a regular expression.  Unlike the &lt;br /&gt;
Caller specifies the aspect class and methods to call before and after each method invocation. A regular expression is used to match on target class names, and either the target methods can be provided or a regu&lt;br /&gt;
&lt;br /&gt;
Specifies an aspect class and advice methods to call before and after method invocations in one or more target classes and methods.  The target classes are speci&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36772</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36772"/>
		<updated>2010-10-05T14:40:47Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR ==&lt;br /&gt;
&lt;br /&gt;
=== Defining Aspects and wrapping methods ===&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; takes the following parameters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - The target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - Wrapper method to call before an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - Wrapper method to call after an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - Methods from the target class, or a regular expression matching method names from the target class, to be intercepted&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following instance methods are inherited from the Aspect class.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - This is the main utility method which allows you to specify an advice method in the aspect class to be invoked before and after each intercepted method, along with the target class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.  &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - Undoes a wrapping made with the previous method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;add_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Allows you to specify an advice method to be called when the joinpoint is reached in the specified target class and method. Joinpoint must be either &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;remove_advice (target, joinpoint, method, advice)&amp;lt;/code&amp;gt; - Removes an advice made with the &amp;lt;code&amp;gt;add_advice&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;disable_advice_dispatching&amp;lt;/code&amp;gt; - Disables all dispatching of advice methods in the program.&lt;br /&gt;
&lt;br /&gt;
* get_methods (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* prepare (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrap_with_code (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrappable? (AspectR::Aspect)&lt;br /&gt;
&lt;br /&gt;
The following class methods are inherited from the Aspect class:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;new (never_wrap = &amp;quot;^$ &amp;quot;)&amp;lt;/code&amp;gt; - &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;dispatch?&amp;lt;/code&amp;gt; - Returns true if dispatching to advice methods is enabled, false if disabled. &lt;br /&gt;
&lt;br /&gt;
The following utility methods are provided by the AspectR library:&lt;br /&gt;
 &lt;br /&gt;
* &amp;lt;code&amp;gt;all_classes (regexp = /^.+$/)&amp;lt;/code&amp;gt; - Returns all classes whose class name matches a given regular expression.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap_classes (aspect, pre, post, classes, *methods)&amp;lt;/code&amp;gt; - More flexible yet experimental version of the &amp;lt;code&amp;gt;wrap&amp;lt;code&amp;gt; method to wrap methods in multiple classes. Caller must provide the aspect object and regular expression used to match target classes.  The rest of the parameters are the same as the &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; method. Note that this API is likely to change in future versions of AspectR.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wraps methods in one or more classes whose class name matches a regular expression.  Unlike the &lt;br /&gt;
Caller specifies the aspect class and methods to call before and after each method invocation. A regular expression is used to match on target class names, and either the target methods can be provided or a regu&lt;br /&gt;
&lt;br /&gt;
Specifies an aspect class and advice methods to call before and after method invocations in one or more target classes and methods.  The target classes are speci&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36771</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36771"/>
		<updated>2010-10-05T14:12:34Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Other methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR ==&lt;br /&gt;
&lt;br /&gt;
=== Defining Aspects and wrapping methods ===&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; takes the following parameters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - The target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - Wrapper method to call before an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - Wrapper method to call after an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - Methods from the target class, or a regular expression matching method names from the target class, to be intercepted&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are inherited from the Aspect class.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; - This is the main utility method which allows you to specify a wrapper method to be invoked before and after each intercepted method, along with the class and an &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; parameter which may contain the methods in the target class to intercept, or a regular expression to match method names in the target class.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;unwrap&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* add_advice (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* all_classes (AspectR) &lt;br /&gt;
&lt;br /&gt;
* disable_advice_dispatching (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* dispatch? (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* get_methods (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* new (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* prepare (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* remove_advice (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrap_classes (AspectR) &lt;br /&gt;
&lt;br /&gt;
* wrap_with_code (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrappable? (AspectR::Aspect)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36770</id>
		<title>CSC/ECE 517 Fall 2010/ch3 3d mr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_3d_mr&amp;diff=36770"/>
		<updated>2010-10-05T14:08:10Z</updated>

		<summary type="html">&lt;p&gt;Mwroda: /* Defining Aspects and wrapping methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Aspect-oriented programming and AspectR =&lt;br /&gt;
&lt;br /&gt;
AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging.  Show how the example would be implemented in AspectJ and AspectR.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
== AspectR ==&lt;br /&gt;
&lt;br /&gt;
=== Defining Aspects and wrapping methods ===&lt;br /&gt;
&lt;br /&gt;
AspectR provides a simple mechanism for wrapping methods in a program. One begins by creating an &amp;quot;aspect&amp;quot; class that inherits from the AspectR Aspect class.  You then define the wrapper methods which will be called at the join points in the program. These methods are called Advice methods. AspectR currently supports only two method join points, &amp;lt;code&amp;gt;PRE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt;. The inherited instance method &amp;lt;code&amp;gt;wrap&amp;lt;/code&amp;gt; is then used to specify the wrapper methods to be called before and after a method invocation, along with the target class and methods to be intercepted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;wrap (target, pre, post, *args)&amp;lt;/code&amp;gt; takes the following parameters:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt; - The target class&lt;br /&gt;
* &amp;lt;code&amp;gt;pre&amp;lt;/code&amp;gt; - Wrapper method to call before an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;post&amp;lt;/code&amp;gt; - Wrapper method to call after an intercepted method call&lt;br /&gt;
* &amp;lt;code&amp;gt;*args&amp;lt;/code&amp;gt; - Methods from the target class, or a regular expression matching method names from the target class, to be intercepted&lt;br /&gt;
&lt;br /&gt;
=== Other methods ===&lt;br /&gt;
&lt;br /&gt;
* unwrap (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* add_advice (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* all_classes (AspectR) &lt;br /&gt;
&lt;br /&gt;
* disable_advice_dispatching (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* dispatch? (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* get_methods (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* new (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* prepare (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* remove_advice (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrap_classes (AspectR) &lt;br /&gt;
&lt;br /&gt;
* wrap_with_code (AspectR::Aspect) &lt;br /&gt;
&lt;br /&gt;
* wrappable? (AspectR::Aspect)&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
The code examples implement a code [http://en.wikipedia.org/wiki/Profiling_%28computer_programming%29 profiler] to measure the duration of method calls.&lt;br /&gt;
&lt;br /&gt;
=== AspectR ===&lt;br /&gt;
&lt;br /&gt;
 require aspectr.rb&lt;br /&gt;
 include AspectR&lt;br /&gt;
 &lt;br /&gt;
 class Profiler &amp;lt; Aspect&lt;br /&gt;
   def method_start(method, object, exitstatus, *args)&lt;br /&gt;
     @begin = Time.now&lt;br /&gt;
   end&lt;br /&gt;
   def method_end(method, object, exitstatus, *args)&lt;br /&gt;
     timeElapsed = Time.now - @begin&lt;br /&gt;
     puts &amp;quot;#{object.class}.#{method} took #{timeElapsed} secs&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 #if $0 == __FILE__&lt;br /&gt;
   class SomeClass&lt;br /&gt;
     def some_method&lt;br /&gt;
       puts &amp;quot;hello&amp;quot;&lt;br /&gt;
       sleep 5&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   Profiler.new.wrap(SomeClass, :method_start, :method_end, /some/)&lt;br /&gt;
   SomeClass.new.some_method&lt;br /&gt;
 #end&lt;br /&gt;
&lt;br /&gt;
=== AspectJ ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;/div&gt;</summary>
		<author><name>Mwroda</name></author>
	</entry>
</feed>