1 / 21

SENG 531: Labs

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.

stew
Download Presentation

SENG 531: Labs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Labs This Week: • Monday • Aspects & AspectJ • Wednesday • Open Lab

  3. 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

  4. 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

  5. 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

  6. 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.

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

  8. 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

  9. 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

  10. 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

  11. Example: Join Points and Pointcuts

  12. 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.

  13. Example: The HelloWorld Plugin

  14. Example: Aspect

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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.

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

  21. Labs Next Week: • Monday • Open • Demo Sign-ups • Wednesday • Open

More Related