Aspect-oriented Software Development - .1 VUB Programming Technology Lab Aspect-oriented Software

  • View
    213

  • Download
    0

Embed Size (px)

Text of Aspect-oriented Software Development - .1 VUB Programming Technology Lab Aspect-oriented Software

  • 1

    VUB Programming Technology Lab

    Aspect-oriented Software Development

    An Introduction

    Johan Brichau

    Inno.com 2 VUB Programming Technology Lab

    Talk Contents

    • Separation of Concerns – Broader Context of AOSD

    • Aspect-orientation – Definition, History

    • Ready-to-use Technologies – An overview

    • Research activities • AspectJ demo

  • 2

    Inno.com 3 VUB Programming Technology Lab

    Talk Contents

    • Separation of Concerns • Aspect-orientation • Ready-to-use Technologies • Research activities • AspectJ demo

    Inno.com 4 VUB Programming Technology Lab

    Separation of Concerns

    • E.W. Dijkstra, Parnas • Organize code according to common

    functionality – Modular programming – Need for programming language mechanisms

    • enforce encapsulation of module internals • provide module composition mechanisms

    • Benefits: – Manage complexity – Fewer defects, easier to localize defects – Reusability – Ability to respond to market changes

  • 3

    Inno.com 5 VUB Programming Technology Lab

    Structured Programming

    • Tangling from explicit gotos • Recognized common control structures

    – capture in more explicit form

    • Resulting code – more clear, easier to write, maintain, debug etc.

    i = 1 TEST: if i < 4 then goto BODY else goto END

    BODY: print(i) i = i + 1 goto TEST END:

    i = 1 while (i < 4) { print(i) i = i + 1 }

    Inno.com 6 VUB Programming Technology Lab

    But… still tangled main () { draw_label(“Haida Art Browser”); m = radio_menu( {“Whale”, “Eagle”, “Dogfish”}); q = button_menu({“Quit”}); while ( ! check_buttons(q) ) { n = check_buttons(m); draw_image(n); } }

    draw_label (string) { w = calculate_width(string); print(string, WINDOW_PORT); set_x(get_x() + w); }

    draw_image (img) { w = img.width; h = img.height; do (r = 0; r < h; r++) do (c = 0; c < w; c++) WINDOW[r][c] = img[r][c]; }

    radio_menu(labels) { i = 0; while (i < labels.size) { radio_button(i); draw_label(labels[i]); set_y(get_y() + RADIO_BUTTON_H); i++; } }

    draw_circle (x, y, r) { %%primitive_oval(x, y, 1, r); }

    radio_button (n) { draw_circle(get_x(), get_y(), 3); }

    button_menu(labels) { i = 0; while (i < labels.size) { draw_label(labels[i]); set_y(get_y() + BUTTON_H); i++; } }

  • 4

    Inno.com 7 VUB Programming Technology Lab

    Group functionality… main () { draw_label(“Haida Art Browser”); m = radio_menu( {“Whale”, “Eagle”, “Dogfish”}); q = button_menu({“Quit”}); while ( ! check_buttons(q) ) { n = check_buttons(m); draw_image(n); } }

    draw_label (string) { w = calculate_width(string); print(string, WINDOW_PORT); set_x(get_x() + w); }

    draw_image (img) { w = img.width; h = img.height; do (r = 0; r < h; r++) do (c = 0; c < w; c++) WINDOW[r][c] = img[r][c]; }

    radio_menu(labels) { i = 0; while (i < labels.size) { radio_button(i); draw_label(labels[i]); set_y(get_y() + RADIO_BUTTON_H); i++; } }

    draw_circle (x, y, r) { %%primitive_oval(x, y, 1, r); }

    radio_button (n) { draw_circle(get_x(), get_y(), 3); }

    button_menu(labels) { i = 0; while (i < labels.size) { draw_label(labels[i]); set_y(get_y() + BUTTON_H); i++; } }

    Inno.com 8 VUB Programming Technology Lab

    …into Modules… main () { draw_label(“Haida Art Browser”); m = radio_menu( {“Whale”, “Eagle”, “Dogfish”}); q = button_menu({“Quit”}); while ( ! check_buttons(q) ) { n = check_buttons(m); draw_image(n); } }

    draw_label (string) { w = calculate_width(string); print(string, WINDOW_PORT); set_x(get_x() + w); }

    draw_image (img) { w = img.width; h = img.height; do (r = 0; r < h; r++) do (c = 0; c < w; c++) WINDOW[r][c] = img[r][c]; }

    radio_menu(labels) { i = 0; while (i < labels.size) { radio_button(i); draw_label(labels[i]); set_y(get_y() + RADIO_BUTTON_H); i++; } }

    draw_circle (x, y, r) { %%primitive_oval(x, y, 1, r); }

    radio_button (n) { draw_circle(get_x(), get_y(), 3); }

    button_menu(labels) { i = 0; while (i < labels.size) { draw_label(labels[i]); set_y(get_y() + BUTTON_H); i++; } }

    But: variations on modules are incredibly complex

  • 5

    Inno.com 9 VUB Programming Technology Lab

    …Object-orientation

    display: boxes, labels click: highlight

    display: boxes, maybe checks, labels click: set/clear

    display: circle, maybe dots, labels click: set/clear AND clear others

    ToggleButtonMenu

    CheckBoxMenu RadioButtonMenu

    Menu

    ButtonMenu

    display: click:

    click: set/clear

    Inno.com 10 VUB Programming Technology Lab

    But…

  • 6

    Inno.com 11 VUB Programming Technology Lab

    But… (example)

    Where is logging in Apache web server ? • Not in one place • Not even in a small number of places

    Inno.com 12 VUB Programming Technology Lab

    Crosscutting Concerns

    • Concern – ‘Something the programmer should care about’ – Ideally implemented in one single module

    • Crosscutting – Implementation is spread across other modules – Difficult to understand, change, maintain, etc…

    • Tyranny of the Dominant Decomposition – Given one of many decompositions of the

    problem… • Mostly core functionality concerns

    – …some subproblems (concerns) cannot be modularized

    • Non-functional, functional, added later on,…

  • 7

    Inno.com 13 VUB Programming Technology Lab

    Tangling -> Structure i = 1 while (i < 5) { print(i) i = i + 1 }

    structured control

    constructs

    i = 1 TEST: if i < 5 then goto BODY else goto END

    BODY: print(i) i = i + 1 goto TEST END:

    menus

    graphics

    simple_browser modules with narrow

    interfaces

    main () { draw_label(“Haida Browser”); m = radio_menu( {“Whale”, “Eagle”, “Dogfish”}); q = button_menu({“Quit”}); while ( ! check_buttons(q) ) { n = check_buttons(m); draw_image(n); } }

    draw_label (string) { w = calculate_width(string); print(string, WINDOW_PORT); set_x(get_x() + w); }

    draw_image (img) { w = img.width; h = img.height; do (r = 0; r < h; r++) do (c = 0; c < w; c++) WINDOW[r][c] = img[r][c]; }

    radio_menu(labels) { i = 0; while (i < labels.size) { radio_button(i); draw_label(labels[i]); set_y(get_y() + RADIO_BUTTON_H); i++; } }

    draw_circle (x, y, r) { %%primitive_oval(x, y, 1, r); }

    radio_button (n) { draw_circle(get_x(), get_y(), 3); }

    button_menu(labels) { i = 0; while (i < labels.size) { draw_label(labels[i]); set_y(get_y() + BUTTON_H); i++; } }

    aspects

    AbstractButton

    Button ToggleButton

    RadioButtonCheckBox

    classification & specialization

    of objects

    menus

    graphics

    simple_browser

    Inno.com 14 VUB Programming Technology Lab

    Talk Contents

    • Separation of Concerns • Aspect-orientation • Ready-to-use Technologies • Research activities • AspectJ demo

  • 8

    Inno.com 15 VUB Programming Technology Lab

    Aspect-orientation

    • Modularize crosscutting concerns – Code scattering (one concern in many modules)

    – Code Tangling (one module, many concerns)

    Inno.com 16 VUB Programming Technology Lab

    Examples?

    • What is an Aspect? vs. What is an Object? • Non-functional aspects

    – Synchronisation – Logging – Error Handling – Persistence – Real-time issues

    • Functional aspects – Coloring of figures in a drawing application – User interface – Personalisation of E-commerce application

  • 9

    Inno.com 17 VUB Programming Technology Lab

    AO History

    • Reflection – Meta-object protocol (MOP)

    • Control over method invocation, instance creation, etc…

    – Often used to implement crosscutting concerns – Considered too powerful and too difficult

    • AOSD – Provide necessary abstractions to implement

    crosscutting concerns • Instead of all reflection possibilities

    – Is often implemented through MP and reflection

    Inno.com 18 VUB Programming Technology Lab

    AO History

    • Domain-specific Aspect Languages – Language targeted towards one kind of aspect

    • COOL & RIDL (Synchronisation) • RG (Loop fusion optimization)

    – describe a concern – Easy to understand – But

    • Limited in expressiveness • New Language for each kind of aspect??

    • General-purpose Aspect Languages – More-gen