90 likes | 315 Views
Software Engineering Lecture 7. Vladimir Safonov , Professor, head of laboratory St. Petersburg University Email: v_o_safonov@mail.ru WWW: http://user.rol.ru/~vsafonov. Aspect-oriented programming (AOP): Aspect. Aspect – an implementation of a crosscutting concern
E N D
SoftwareEngineeringLecture7 Vladimir Safonov, Professor, head of laboratory St. Petersburg University Email: v_o_safonov@mail.ru WWW: http://user.rol.ru/~vsafonov
Aspect-oriented programming (AOP): Aspect • Aspect – an implementation of acrosscutting concern • Aspect – special kind of a module to be used by itsweaving into other modules • Examples of aspects: - implementation of MT safety for an existing library - implementation of a new source language feature in a compiler So aspects are ubiquitous in programming, but still added and located “by hand”, hence the modularity and maintenance issues (C) Vladimir O. Safonov, 2004
The structure of aspect definition (V. Safonov) • Aspect name • Aspect parameters (optional) – generic aspects desirable • Aspect data • Aspect modules • Aspect actions, with their weaving rules • A separate reusable sets of weaving rules possible, to be used when weaving different aspects (C) Vladimir O. Safonov, 2004
Aspects – static or dynamic? • First view on aspects: Aspect weaving is a kind of “tangled macro expansion”: • Second view: Aspect weaving is performed dynamically, at runtime if Condition then Action (looks like debugging breakpoints – well know for years) • Our viewpoint (V. Safonov): we take the static view but do recognize the dynamic view should be also implemented (C) Vladimir O. Safonov, 2004
Aspects inAspectJ (1/2) • AspectJ: Xerox PARC (1995) -> Univ. of British Columbia, Canada (2003), designed by prof. Gregor Kichales • AspectJ – aspect-oriented extension of Java (compiler from the extended language, debugger in terms of aspects, Aspect GUI) • Pointcut – definition of a group of weaving rules(using wildcards for entity names), - not tied to a concrete code • Join points – concrete points in concrete code to be modified inaspect weaving • Advices – actions to be performed at join points (C) Vladimir O. Safonov, 2004
Aspects inAspectJ (2/2) • Aspects in AspectJ are essentially dynamic (similar to debugging-style breakpoints/debugging actions) • Introduce – weaving new definitions into a module; these definitions are visible by the aspect only (no encapsulation violation happens) • around S A -> B - AspectJstyle of code modification at runtime (self-modifying code); actually, AspectJ behaves as term rewriting system. • Our viewpoint: this is a powerful tool but potentially dangerous (C) Vladimir O. Safonov, 2004
Aspects in Aspect.NET (V. Safonov) • Static approach to AOP very important: it improves program readability • Aspects for .NET should be cross-language • Using custom attributes (AspectDef, AspectRef) • Syntactic sugar: a simple AOP annotations meta-language converted to AOP attributes • Aspectizing (classical term – aspect mining): turning non-AOP programs into AOP ones (coloring the aspects) • Aspect GUI • Aspect.NET site: http://aspect-dot-net.sscli.net (C) Vladimir O. Safonov, 2004
Other new programming paradigms • Logic programming • Functional programming • Event-driven programming • Generic programming • Meta-programming (C) Vladimir O. Safonov, 2004
Home task and references to lecture 7 • http://aosd.net - the main Web site on AOP • http://aspectj.org - theAspectJ Web site • Safonov V. O. Aspect.NET – a new approach to aspect-oriented programming. – In: “.NET Developer’s Journal”, 2003, # 4. (C) Vladimir O. Safonov, 2004