21
SENG 531: Labs TA: Brad Cossette [email protected] [email protected] http://pages.cpsc.ucalgary.ca/ ~cossette/ Office Hours: Monday, Wednesday 3-4pm ICT 524

SENG 531: Labs

  • Upload
    stew

  • View
    51

  • Download
    0

Embed Size (px)

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 Presentation

Citation preview

Page 1: SENG 531: Labs

SENG 531: Labs

TA: Brad [email protected]

[email protected]

http://pages.cpsc.ucalgary.ca/~cossette/

Office Hours:Monday, Wednesday 3-4pm ICT 524

Page 2: SENG 531: Labs

Labs This Week:

MondayAspects & AspectJ

WednesdayOpen Lab

Page 3: SENG 531: Labs

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

Page 4: SENG 531: Labs

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

Page 5: SENG 531: Labs

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

Page 6: SENG 531: Labs

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.

Page 7: SENG 531: Labs

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.

Page 8: SENG 531: Labs

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

Page 9: SENG 531: Labs

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

Page 10: SENG 531: Labs

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

Page 11: SENG 531: Labs

Example: Join Points and Pointcuts

Page 12: SENG 531: Labs

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.

Page 13: SENG 531: Labs

Example: The HelloWorld Plugin

Page 14: SENG 531: Labs

Example: Aspect

Page 15: SENG 531: Labs

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

Page 16: SENG 531: Labs

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

Page 17: SENG 531: Labs

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

Page 18: SENG 531: Labs

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

Page 19: SENG 531: Labs

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.

Page 20: SENG 531: Labs

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. =)

Page 21: SENG 531: Labs

Labs Next Week:

MondayOpenDemo Sign-ups

WednesdayOpen