Separation of Concerns (Soc) and Aspect-Oriented Programming (AOP)

Separation of Concerns (Soc) and Aspect-Oriented Programming (AOP)

Separation of Concerns (SoC) and “To my taste the main characteristic of intelligent thinking is that one is willing and able to study in Aspect-Oriented Programming (AOP) depth an aspect of one's subject matter in isolation, for the sake of its own consistency, all the time knowing that one is occupying oneself with only one of the aspects. The other aspects have to wait their turn, because our heads are so small Department of Computer Science and Software Engineering that we cannot deal with them simultaneously Concordia University without getting confused. […] Summer 2013 1 2 Separation of Concerns (SoC) • “Separation of Concerns” (Dijkstra, Parnas): realization I usually refer to it as Separation of Concerns, of problem domain concepts into separate units of because one tries to deal with the difficulties, the software. obligations, the desires, and the constraints one by one.” • There are many benefits associated with having a concern of a software system being expressed in a E. W. Dijkstra, A Discipline of Programming, single modular unit. 1976, last chapter, In Retrospect – Better analysis and understanding of systems, easy adaptability, maintainability and high degree of reusability. • Crucial to software development. • How to best achieve it is an open issue. 3 4 From machine language to assembly Unstructured programming programming i = 1 • Machine language: 10110000 01100001 Program TEST: if i < 4 then goto BODY Main program else goto END • Equivalent assembly BODY: print(i) i = i + 1 representation: mov al, 061h goto TEST END: which means to move the hexadecimal value 61 (97 • With GOTO, no control structures. decimal) into the processor register with the name "al". • Escapes from machine dominance, but it was still low level and tedious. • It resembles the way a machine is organized. • Complex code: Difficult to read and write. • Poor evolvability. • Tedious and error prone. • Poor maintainability. • Poor reusability. 5 6 1 Procedural programming Structured programming Program Main program Program i = 1 while (i < 4) { Main program print(i) Procedure 1 Procedure 2 i = i + 1 } Procedure n • Enabled developers to adopt high-level language • + Procedural abstractions + Parameter passing + constructs. Recursion; Program = data structures + functions. • Language features for common program patterns. • Allows functional decomposition of a problem. • Support for control flow: selection and loop. • Top-town design and stepwise refinement allow the • Allowed (some) abstraction from the underlying machine. problem to be broken down into (manageable) • Poor evolvability. subproblems. • Poor maintainability. • Modular composition is made possible as solutions to • Poor reusability. subproblems can be coded into units of functionality 7 (procedures and functions) or components. 8 Object-oriented programming (OOP) Program Object 1 • Inheritance allows for reusing implementation and Object 4 interface, to support an is-a relationship: specialization, Object 2 specification, extension, and combination. Object 3 • Composition can describe a has-a relationship. • Polymorphism provides a common behavior and interface for related concepts. • + Encapsulation + Polymorphism + Inheritance • Provides linguistic mechanisms to support functional • Overall, OOP gets closer to the way we think. decomposition along the notion of class. • Has been a great success towards SoC. • Allows us to view computation as a set of collaborating objects. • Classes allow us to hide implementation details beneath interfaces. 9 10 The origins of OOP “The purpose of thinking is to reduce the detailed reasoning • OOP is an evolutionary, not a revolutionary approach. needed to a doable amount, and a separation of concerns is the way we hope to achieve this reduction. The crucial choice is, of course, what aspects to study in isolation, how to disentangle the original amorphous knot of obligations, constraints and goals into a set of concerns that admit a reasonably effective separation. The knowledge of the goal of separation of concerns is a useful one: we are at least beginning to understand what we are aiming at.” E. W. Dijkstra, A Discipline of Programming, 1976, last chapter, In Retrospect. 11 12 2 Languages and paradigms Paradigms and complexity • Programming languages and paradigms define the way • Evolution of programming paradigms lets us we communicate with machines. manage the increasing complexity of systems. • Each paradigm offers its own set of decomposition rules through linguistic mechanisms. • The converse of this fact is equally true (and – e. g. procedures, functions, objects, etc. very itinteres ti)Wting): We have a llowe dthd the ex itistence of increasingly complex requirements because • Each paradigm has advanced our ability to achieve clear separation of concerns at the source code level. various paradigms provide mechanisms to – It allows a more natural mapping of requirements to support their implementation. programming constructs. – Problem decomposition and programming languages have been mutually supportive. • From conventional to intelligent computing 13 14 Programming language paradigms and Crosscutting thought • In OOP, decomposition (through mechanisms • Does a natural language affect the way we think? provided by current languages) is one-dimensional – Discovery channel had a documentary about a tribe that has no focusing on the notion of a class. notion of numbers. – So we cannot say things like “how many?”, “in fifteen minutes”, • In large systems, interaction of components is very etc. complex. • Does a programming language paradigm affect the way • Current programming languages do not provide we think about providing solutions to problems? constructs to address certain properties in a – We tend to perform functional decomposition and stepwise modular way. refinement of problems in terms of programming constructs (procedures, objects, functions, etc.) • OOP cannot address the design or implementation of behavior that spans over many modules (often unrelated). 15 16 A first example of crosscutting An initial picture of crosscutting • Authentication, contract checking and logging are Component Component Component tangled with the core operation (methods) of the component (class). public class BusinessLogic { // data members for business logic, authentication, contract checking, logging. public void someOperation { // perform authentication // ensure preconditions // log the start of an operation … perform core operation // authentication // ensure postconditions // log successful termination of // operation } 17 // more operations similar to the above} 18 3 Some observations Symptoms of crosscutting Two issues are of interest here: • Crosscutting imposes two symptoms on software development: 1. Implementation for authentication, contract checking – Code scattering: implementation of some concerns not well and logging is not localized. modularized but cuts across the decomposition hierarchy of the – CdCode spans over many meth thdods of pot enti tillally many c lasses system. and packages. – Code tangling: a module may contain implementation elements (code) for various concerns. 2. Implementation of someOperation() does much more than performing some core functionality. • Scattering and tangling describe two different facets of – It contains code for more than one concerns. the same problem. 19 20 Where does crosscutting originate? Implications of crosscutting • There might not always be a one-to-one mapping from • As a result of crosscutting, the benefits of OOP cannot problem domain to solution space. be fully utilized, and developers are faced with a • Requirements space is n-dimensional, but number of implications: Implementation space is one-dimensional (In OOP everything must belong to a class). – Poor traceability of requirements: Mapping from an n- dimens iona l space to a s ing le dimens iona l imp lemen ta tion Requirements Implementation space. R 1 C1 – Lower productivity: Simultaneous implementation of multiple concerns in one module breaks the focus of developers. R2 C2 R3 C3 – Strong coupling between modular units in classes that are R4 C4 difficult to understand and change. scattering tangling 21 22 We would like to move from this picture… Component Component Component – Low degree of code reusability. Core functionality impossible to be reused without related semantics, already embedded in component. – Low level of system adaptability. – Changes in the semantics of one crosscutting concern are difficult to trace among various modules that it spans over. – Programs are more error prone. – Difficult evolution. • Crosscutting affects the quality of software. 23 24 4 …to this one! aspects Aspect-oriented programming (AOP) component component component • Motivation: Better linguistic mechanisms are needed for SoC. • Aspect-Oriented Programming (AOP) refers to approaches and technologies that can explicitly capture crosscutting concerns. – Concerns can be functional ((ge.g. business rules) or non- functional (e.g. synchronization). • In OOP, the tendency is to find commonality among classes and push them up (vertically) in the inheritance hierarchy. • In AOP, we identify scattered concerns and eject them horizontally from the object structure. We want to provide a new unit of modularity, • Just as OOP did not discard the idea of block structure that explicitly captures a crosscutting concern. and structured programming, AOP does not reject existing technology. 25 26 Principles of AOP: 1. Quantification whenever

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us