210 likes | 314 Views
SENG 531: Labs. TA: Brad Cossette brad.cossette@gmail.com cossette@cpsc.ucalgary.ca 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.
E N D
SENG 531: Labs TA: Brad Cossette brad.cossette@gmail.com cossette@cpsc.ucalgary.ca 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 • 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: • A pointcut you want the advice to execute on • When you want the advice to happen • A method body
Aspects: The Practical Part At their simplest, Aspects are weaving two different pieces of code together. • Figure out where you want to splice in code • Figure out how to describe those points in a pointcut pattern • Write what you want to have happen at that pointcut.
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 correctly • Getting 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 projects • AspectJ 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 Guide http://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 output • Text Input should accept a path to a file as a text string • How 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 time • You will not be docked marks on the correctness of your ASTParsing anymore. =)
Labs Next Week: • Monday • Open • Demo Sign-ups • Wednesday • Open