<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nicholas Pike &#187; aspect orientated programming</title>
	<atom:link href="http://blog.npike.net/category/aspect-orientated-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.npike.net</link>
	<description>Like nailing jelly to a wall...</description>
	<lastBuildDate>Tue, 20 Jul 2010 05:45:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8230; AspectJ Orientated Programming Continued</title>
		<link>http://blog.npike.net/2008/01/07/aspectj-orientated-programming-continued/</link>
		<comments>http://blog.npike.net/2008/01/07/aspectj-orientated-programming-continued/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 01:06:29 +0000</pubDate>
		<dc:creator>npike</dc:creator>
				<category><![CDATA[aspect orientated programming]]></category>
		<category><![CDATA[aspectj]]></category>

		<guid isPermaLink="false">http://blog.npike.net/2008/01/07/aspectj-orientated-programming-continued/</guid>
		<description><![CDATA[Last month I wrote briefly about a computer science seminar course that I am taking, Programing Skills: Aspect Orientated Programming.
The best way to show the differences between AOP and the &#8220;classic&#8221; OOP (object orientated programming) paradigm is the Observerable design pattern.
For example:  Take a LinkedList that you wish to monitor.

Whenever the list is changed, [...]]]></description>
			<content:encoded><![CDATA[<p>Last <a href="http://blog.npike.net/2007/12/03/vacation-is-over-back-to-being-schooled/">month</a> I wrote briefly about a computer science seminar course that I am taking, Programing Skills: Aspect Orientated Programming.</p>
<p>The best way to show the differences between AOP and the &#8220;classic&#8221; OOP (object orientated programming) paradigm is the Observerable design pattern.</p>
<p>For example:  Take a LinkedList that you wish to monitor.</p>
<ul>
<li>Whenever the list is changed, print &#8220;List is changed&#8221;</li>
<li>Whenever the list is changed, print if the list is empty</li>
</ul>
<p>To do this with the classic OOP Observable pattern, you have to create two Observer classes (extending some sort of super Observer class ), make your LinkedList implement the Observerable class, and make a test class to attach said Observers to your LinkedList.</p>
<p>To do the same in AOP, you simply make an Aspect &#8211; that watches when your class has been accessed, and acts accordingly based on <em>advice</em> that you give it.</p>
<p>Code below, read entire post for snippets.</p>
<p><span id="more-104"></span></p>
<pre name="code" class="java">
import edu.rit.cs.helio.util.LinkedList;

/**
 * @author Nicholas Pike (nsp1828)
 *
 * AbstractObserver contains only a single pointcut, which is shared
 * for other observers observing the home-brew LinkedList class
 *
 */
public abstract aspect AbstractObserver {
	pointcut change(LinkedList list):
		target (list) &#038;&#038;
		!within(LinkedList) &#038;&#038;
		(call(void LinkedList.append(*)) ||
		call(void LinkedList.rotate(*)) ||
		call(void LinkedList.sort()) ||
		call(void LinkedList.prepend(*)) ||
		call(void LinkedList.discard_first()) ||
		call(void LinkedList.discard_last()));
}
</pre>
<pre name="code" class="java">
import edu.rit.cs.helio.util.LinkedList;

/**
 * @author Nicholas Pike (nsp1828)
 *
 * Extends AbstractObserver, which contains our pointcut that is used
 * to observe the home-brew LinkedList class
 *
 */
public aspect EmptyObserver extends AbstractObserver {

	after(LinkedList list) returning: change(list) {
		if (list.is_empty()) {
			System.out.println("\tList is empty.");
		} else {
			System.out.println("\tList is not empty.");
		}
	}
}
</pre>
<pre name="code" class="java">
import edu.rit.cs.helio.util.*;

/**
 * @author Nicholas Pike (nsp1828)
 *
 * Extends AbstractObserver, which contains our pointcut that is used
 * to observe the home-brew LinkedList class
 *
 */
public aspect ListObserver extends AbstractObserver {

	after(LinkedList list) returning: change(list) {
		System.out.println("\tChanged:"+list.toString());
	}
}
</pre>
<p>Then using the &#8220;ajc&#8221; compiler (a special java compiler), the byte code of your resulting classes are modified to support aspects, which can then be run by any java runtime.  There&#8217;s no need to explicitly attach the &#8220;Observer Aspects&#8221; to your classes for them to observe them.  Just compile then alongside everything else!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.npike.net/2008/01/07/aspectj-orientated-programming-continued/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
