seng 531: labs
DESCRIPTION
SENG 531: Labs. TA: Brad Cossette [email protected] [email protected] http://pages.cpsc.ucalgary.ca/~cossette/ Office Hours: Monday, Wednesday 3-4pm ICT 524. Labs This Week:. Monday Aspects & AspectJ Wednesday Open Lab. Aspects Intro: Separation of Concerns. - PowerPoint PPT PresentationTRANSCRIPT
SENG 531: Labs
TA: Brad [email protected]
http://pages.cpsc.ucalgary.ca/~cossette/
Office Hours:Monday, Wednesday 3-4pm ICT 524
Labs This Week:
MondayAspects & AspectJ
WednesdayOpen Lab
Aspects Intro:Separation of Concerns Normally when you do an OO design, you
try to break down each problem into small, independent chunks.
Ideally, each chunk/class/package etc. handles just one specific thing, or part of the problem
Cohesion and Separation of Concerns High Cohesion is Generally a Good
Thing™ Ideally, each Class only has functionality
specific to its role
You can’t always get good Cohesion Real code usually needs to do more then 1
thing
Aspects: How does this help?
Think about Refactoring in OO If you have a bunch of classes with
common functionality, move that into a super class
Aspects: How does this help?
Aspects work similarly Move the common functionality into an
Aspect Provide directions in the Aspect to tell the
compiler where the functionality needs to happen in the actual code.
Aspects: What about Evolution?
You can use aspects to modify code without touching it (in theory)*
Put the new code in the Aspects Provide directions in the Aspect to tell the
compiler where: the functionality needs to add to code the functionality needs to override code.
Aspects: Terminology
Join Point
A point in the code that an Aspect can grab a reference to and do things.
Join Points are limited to: method calls method executions object instantiations constructor executions field references
Source: http://www.eclipse.org/aspectj/doc/released/progguide/language-joinPoints.html
Aspects: Terminology
Pointcut
A pattern that describes one or more Join Points. Pointcuts let you define: A target class/method/type The context in which it is executed Boolean operations to combine multiple
Pointcut patterns
Aspects: Terminology
Advice
What you want to have happen at a pointcut. Advice comprises 3 things:
1. A pointcut you want the advice to execute on
2. When you want the advice to happen
3. A method body
Example: Join Points and Pointcuts
Aspects: The Practical Part
At their simplest, Aspects are weaving two different pieces of code together.
1. Figure out where you want to splice in code
2. Figure out how to describe those points in a pointcut pattern
3. Write what you want to have happen at that pointcut.
Example: The HelloWorld Plugin
Example: Aspect
A few notes
Window is a private field. To access it, I had to modify the base code and add a getter method.One of many things I ended up trying
The mod_hello() pointcut in the example doesn’t map correctlyGetting pointcuts working is deceptively tricky
Key Steps
Download the ApectJ Development Tools (ADJT) from http://www.eclipse.org/ajdt/Don’t forget – you need this installed when
you demo as well!
You have to convert your plug-in projects to AspectJ projectsAspectJ Tools Convert to AspectJ
Gotcha’s!
You can’t access static or private variables
Some of the pointcuts are two sides of the same coin e.g. call() and execution()But! they behave differently because of Single
Dispatch
Context-sensitive help when typing is flaky
Resources
AJDT Main Page: http://www.eclipse.org/ajdt/
AspectJ Development Guidehttp://www.eclipse.org/aspectj/doc/released/progguide/index.html
Safari Tech Books : Eclipse AspectJ: Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools
Notes on Assignment 3
You’re adding on a new input & new outputText Input should accept a path to a file as a
text stringHow you do this is up to you, but hard-coded
solutions will be penalized.
Text-based output is just a console dump, like you did in Assignment 1.Assume it’s within your Java Project.
Notes on Assignment 3
All input/output must be Aspectified™.Any combination of input/output should be
specified at run-time. If a combination does not make sense in your
case, make a design decision and justify it.
The focus is on the Aspects this timeYou will not be docked marks on the
correctness of your ASTParsing anymore. =)
Labs Next Week:
MondayOpenDemo Sign-ups
WednesdayOpen