CSE 503 - Assignment 4

University of Washington

Spring 2004

instructor: Rob DeLine

ta: Miryung Kim

due:Wed 2 Jun 2004

In this assignment, your job is to investigate and understand a large scale software as a developer who joined an open source project recently. You are to work alone on this assignment. You may ask your classmates for clarifications about the assignment, but not discuss solutions. You should feel free to consult the course readings and the lecture notes. You should feel free to use any software engineering tools, but you should specify which tool you used and how it helped your investigation (for example, "I used the grep to search blahblah..."). If you ask us, we can recommend several software engineering tools for you. If you choose to understand the system by reading code, that is perfectly fine with us. You should not consult the internet for solutions to these assignment questions or similar questions, since that would rob you of the opportunity to hone your program investigation skills. You should not consult the authors of the code. Finally, please monitor the course mailing list for questions and clarifications about the assignment. This assignment will be graded based on the quality of your answer.

The project that you will be working on is the JukeX application. JukeX is a flexible jukebox system written entirely in Java. It is reasonably well documented and has comments in the code. The JukeX project is currently during a software maintenance stage (hypothetically for this assignment purpose), and you are asked to understand this software and identify design problems. 

You can download the source code from the following URL (http://sourceforge.net/projects/jukex) Please make sure to download version 0.8 (beta) source code. The name of the source code zip file is jukex-0.8-src.zip .(click on "Files" tab, and you will find it.)

Java Doc of this system can be found in $/jukex/docs/api/index.html. ($ is the directory that you unzipped the source code.) You are not required to understand the functionality of JukeX fully nor run this system to do this assignment. I recommend that you skim the javadoc documentation to understand its organizational structure. Running this system actually requires you to install a few third party modules. If you are very much interested in running this application in order to understand its functionality, please read $/jukex/README file.

1. Identifying modules that violate the Information Hiding principle [30%]

Information Hiding principle is about hiding design decisions that are likely to change. There are many ways to violate this principle. One way of violating this principle is to make assumptions about a callee when the calllee does not intend to expose its inner implementation. For example, both caller and callee make assumptions about each other in the code below.

void Caller () {
	P p = new P1(); // P is a supertype of P1 
	C c = Callee(p); 
	if (c instanceof C1) {//C1 is a subtype of C
		//do something by peeking the actual type of the object returned by the callee
	}
}
C Callee(P p) {
	if (p instanceof P1) {
		//do something by peeking the actual type of the object passed by the caller 
	}
}

In additition, programmers may accidently expose design decisions. For example, returning an internal (private) data object instead of returning a cloned object may give opportunity to other modules to manipulate the internal data object. Implementation details of a module can be exposed accidently by naming your public methods or fields with hints on its internal data type, for example, List::appendAtTheEndOfArray (Object o) instead of List::append (Object o).

A. In the packages of "com.neoworks.jukex", "com.neoworks.jukex.sqlimpl", and "com.neoworks.connectionpool", identify two classes that violate the Information Hiding principle and explain why each class violates Information Hiding principle. Answering this question may involve understanding code in other packages. Your answer should be specific enough so that we can verify your answer based on the code. For example, please tell us what kinds of future changes would be difficult to add, given the design decisions that had been made. Include code snippets, line numbers, and class (method) names if necessary.

B. In the packages of "com.neoworks.jukex", "com.neoworks.jukex.sqlimpl", and "com.neoworks.jukex.onnection", identify one class that does not violate the Informating Hiding principle and explain why the class respects the Information Hiding principle. Answering this question may involve understanding code in other packages. Your answer should be specific enough so that we can verify your answer based on the code. Include code snippets, line numbers, and class (method) names if necessary.

C. Evaluate each class in your answer of A and B in terms of cohesion and coupling. Answering this question may involve understanding code in other packages. In short, we say that a module is cohesive if everything related to a particular design decision is centralized. We say that a module is coupled if it has spagetti-dependencies on other modules. For more information, you can search Google. I found this description  very useful and easy to understand. Your answer should be justified. For example, please tell us which criteria you used to evaluate each class. You may include a diagram that describes dependecies of each class. I recommend that you use UML notation if you decide to draw diagrams to explain dependency structure.

2. Design rationale:  Why do crosscutting concerns appear in the code base? [15%]

In the package of "com.neoworks.jukex.sqlimpl", logging concerns are scattered all over the package, although this application uses a third party logging module(org.apache.log4j). For example, a part of logging concern is found below.

	In the class of JukeXAttributeValue, 
	line 36-38: singleton instance of logging module is retrieved.  
	private static final Category log = Category.getInstance(JukeXAttributeValue.class.getName());
	private static final boolean logDebugEnabled = log.isDebugEnabled();
	private static final boolean logInfoEnabled = log.isInfoEnabled();
	line 105-112:
	if ( !newEntryId.next() )
	{
		log.error("Something awful happened.  An INSERT somehow failed to appear in the database");
	}
	else
	{
		this._attrenumid = newEntryId.getLong( 1 );
	}
	line 115-118:
	catch ( Exception e )
	{
		log.error( "Encountered an exception whilst trying to create a String AttributeValue" , e );
	}
	line 182-185:
	catch ( Exception e )
	{
		log.error("Encountered an exception attempting to change an AttributeValue string value");
	}
	....
	In the class of JukeXPlaylist,
	line 53-55:
	private static final Category log = Category.getInstance(JukeXPlaylist.class.getName());
	private static final boolean logDebugEnabled = log.isDebugEnabled();
	private static final boolean logInfoEnabled = log.isInfoEnabled();
	line 129-132:
	else {
		if (logDebugEnabled) log.debug("I'm spent, delegating...");
		retVal = delegateGetNextTrack();
	}
	line 158:
	if (logDebugEnabled) log.debug("Peeking ahead for " + count + "tracks, remainder " + rem);
	...Many more  
		  
		

Please answer each of following questions.

A. Identify every appearance of logging concern within the package of "com.neoworks.jukex.sqlimpl". Include class names, method names, line numbers, and code snippets, so that we can check your answers. Please explain how you located every apperance of the logging concern.

B. Is it possible to modularize this logging concern in standard Java? If the answer is YES, then please explain how you would modularize the logging concern. If the answer is NO, then please explain what are the primary design decisions that do not allow this logging concern to be modularized. Answering this question may involve understanding code in other packages.

C. Is it possible to modularize this logging concern in AspectJ without refactoring the code? If the answer is YES, then please write down a logging aspect declaration including point-cuts and advice in AspectJ. If the answer is NO, then please explain why it is difficult to write an aspect for this concern.

3. Identifying crosscutting concerns [25%]

The previous question asks about a crosscutting concern that we've identified in the code. This question asks you to find another cross-cutting concern on your own. In the lecture, we discussed many well-known kinds of crosscutting concerns, such as system logging, database transaction, data serialization, runtime invariant checking, network connections, etc. Your job is to identify one crosscutting concern in the packages of
"com.neoworks.jukex.query", "com.neoworks.connectionpool" and "com.neoworks.jukex.sqlimpl"

Please answer each of following questions.

A. How did you identify crosscutting concerns? In other words, what is the symptom of crosscutting concerns that you identified?

B. Write down every appearance of the concern that you identified in the Question A. Please include class names, method names, line numbers, and code snippets, so that we can check your answer based on the code. Please explain why you think the authors could not modularize the crosscutting concern. In other words, what are the primary design decisions that the authors chose and how did the primary concerns not allow the crosscutting concern to be modularized? Answering this question may involve understanding code in other packages.

C. Is it possible to modularize the concern in B in AspectJ programming language without refactoring the code base? If the answer is YES, then please write down an aspect declaration including pointcuts and advice in AspectJ. If the answer is NO, then please explain why it is difficult to write an aspect for this concern.

4. Design Patterns [30%]

In this question, you are to identify how design patterns are instantiated in the JukeX application. To do this assignment, we encourage you to read a few chapters of Gang of Four Design Patterns book. Don't worry, you don't need to read all design patterns in the book. We will guide you which ones you need to know. If you don't have a copy of this book and want to read it, please let me (Miryung) know. We will make photocopies of a few relevant chapters. You may also refer to design patterns tutorials on-line.
(http://www.csc.calpoly.edu/~dbutler/tutorials/winter96/patterns/)
(http://www.research.ibm.com/designpatterns/pubs/dp-tutorial.pdf)
(http://www.cs.unc.edu/~vivek/patterns/doc/)
and many more.....  

A. In the JukeX system, there are extensive uses of Singleton Design Pattern. Your task is to identify an instantiation of Singleton Design Pattern within the packages of "com.neoworks.connectionpool", "com.neoworks.jukex", and "com.neoworks.jukex.sqlImpl". Hint: comments in the code might help you with this question. In your answer, please include names of Singleton class and methods that are used to create a single instance. You may also include relevant code snippets in your answer if necessary.

B. In the packages of "com.neoworks.tracksource.filter", "com.neoworks.jukex.sqlImpl" and "com.neoworks.util", identify an instantiation of one of the following design patterns, Abstract Factory, Factory Method, Template Method, and Strategy

Your answer should include (1) which design pattern is instantiated,  (2) participants of the pattern in the JukeX system, (3) code snippets relevant to the design pattern and their locations. For example, if you found an instantiation of the Strategy pattern, the answer should be (1) Strategy, (2) Context corresponds to JukeContext, ConcreteStrategy corresponds to JukeConcreteStrategy, and Strategy corresponds to JukeStrategy. If you are certain that a particular design pattern appears in the code, but cannot correspond code snippets to the participants described in the book, give us your justification. As you may know, Abstract Factory, Factory Method, and Template Method are very much relevant to each other.

5. Software Engineering Tools - Bonus [5%]

If you used software engineering tools to do this assignment, please specify (1) which tools you used, (2) how they helped your investigation, and (3) limitations of the tools.

Hand-in instructions.

As with assignment 3, you should hand in your assignment both using E-Submit and on paper in lecture.