Unit 4.1
Unit 4.1
CORBA
1.0, IDL 1996
MDA
1997
UML, MOF,
XMI, CWM
2001
The Object Management Group (OMG)
An open membership
Viewpoint: Here ‘abstraction’ is used to mean the process of suppressing selected detail to establish a
simplified model.
Platform: A platform is a set of subsystems and technologies that provide a coherent set of functionality
through interfaces and specified usage patterns, which any application supported by that platform can use
without concern for the details of how the functionality provided by the platform is implemented.
Platform Independence: This is the quality that the model is independent of the features of a platform of any
particular type.
Pervasive Services: Pervasive services are services available in a wide range of platforms.
Model Transformation: Model transformation is the process of converting one model to another model of the
same system.
• Model Driven Architecture (MDA) is an effective design approach
that is taken by developers to capture the project requirements,
plans and implementation design and follow it to implement the
system.
PSM to PSM
mappings
Time
PIM to PSM
mappings
(projection on a
specific platform)
Developing in MDA – Step 1:
the PIM (1/2)
All MDA development projects start with the creation of a PIM
PIM at this level represents business functionality and behaviour,
undistorted by technology details
MDA application-modeling tools contain representations of Pervasive
Services and Domain Facilities allowing them to be used and/or
incorporated in the application via a menu selection
Developing in MDA – Step 2: the PSM
(1/2)
Once the first iteration is complete, the PIM is input to the mapping
step which will produce a PSM
Code is partially automatic and partially hand-written
PIM can be mapped either to a single platform or to multiple
platforms
Developing in MDA – Step 3:Generating Application
(1/2)
• Portability: The migration of existing functionalities to new environments and platforms, as per the
business requirements, can be rapidly done.
• Productivity and Time-to-Market: Many of the tasks are automated and the development team can
concentrate on the core logic. Thus productivity is increased and time to reach market becomes
shorter.
• Quality: The consistency and reliability of the components built, contributes to the overall quality of
the system.
• Integration: The MDA greatly facilitates the production of integration bridges with legacy and/or
external system.
• Maintenance: Since the design is available in a machine-readable form, analysts, developers and
testers can directly access the specifications of the system and thus maintenance process is
simplified.
• Testing and Simulation: The models can be validated against requirements and tested against
various infrastructures.
• Return on Investment: The investments done on tools generates greater value
Aspect Oriented Programming(AOP)
Programming paradigms
• Procedural programming
• Executing a set of commands in a given sequence
• Fortran, C, Cobol
• Functional programming
• Evaluating a function defined in terms of other functions
• Lisp, ML, OCaml
• Logic programming
• Proving a theorem by finding values for the free variables
• Prolog
• Object-oriented programming (OOP)
• Organizing a set of objects, each with its own set of responsibilities
• Smalltalk, Java, C++ (to some extent)
• Aspect-oriented programming (AOP)
• Executing code whenever a program shows certain behaviors
• AspectJ (a Java extension)
• Does not replace O-O programming, but rather complements it
23
The problem
• Some programming tasks cannot be neatly encapsulated in objects,
but must be scattered throughout the code
• Examples:
• Logging (tracking program behavior to a file)
• Profiling (determining where a program spends its time)
• Tracing (determining what methods are called when)
• Session tracking, session expiration
• Special security management
• The result is crosscuting code--the necessary code “cuts across” many
different classes and methods
24
Example
• class Fraction {
int numerator;
int denominator;
...
public Fraction multiply(Fraction that) {
traceEnter("multiply", new Object[] {that});
Fraction result = new Fraction(
this.numerator * that.numerator,
this.denominator * that.denominator);
result = result.reduceToLowestTerms();
traceExit("multiply", result);
return result;
} • Now imagine similar code in
... every method you might want
} to trace
25
Consequences of crosscutting code
• Redundant code
• Same fragment of code in many places
• Difficult to reason about
• Non-explicit structure
• The big picture of the tangling isn’t clear
• Difficult to change
• Have to find all the code involved...
• ...and be sure to change it consistently
• ...and be sure not to break it by accident
• Inefficient when crosscuting code is not needed
26
Why AOP
Aspect oriented programming(AOP)
• Aspect oriented programming(AOP) can be defined as the breaking of code into different
modules, also known as modularization, where the aspect is the key unit of modularity.
• AOP allows us to write application code and middleware services separately and allow to
link middleware services code with application through xml files or annotation.
• AOP breaks the program logic into distinct parts called as concerns.
• A cross-cutting concern is a concern that can affect the whole application and should be
centralized in one location in code as possible, such as transaction management,
authentication, logging, security etc.
• AOP is a programming paradigm that aims to increase modularity by allowing
the separation of cross-cutting concerns.
• It provides the pluggable way to dynamically add the additional concern before, after or around
the actual logic. Suppose there are 10 methods in a class as given below:
class A{
public void m1(){...}
public void m2(){...}
public void m3(){...}
public void m4(){...}
public void m5(){...}
public void n1(){...}
public void n2(){...}
public void p1(){...}
public void p2(){...}
public void p3(){...}
}
• There are 5 methods that starts from m, 2 methods that starts from n and 3
methods that starts from p.
• Understanding Scenario I have to maintain log and send notification after
calling methods that starts from m.
• Problem without AOP We can call methods (that maintains log and sends
notification) from the methods starting with m. In such scenario, we need to
write the code in all the 5 methods.
• But, if client says in future, I don't have to send notification, you need to
change all the methods. It leads to the maintenance problem.
• Solution with AOP We don't have to call methods from the method. Now we
can define the additional concern like maintaining log, sending notification etc.
in the method of a class. Its entry is given in the xml file.
• In future, if client says to remove the notifier functionality, we need to change
only in the xml file. So, maintenance is easy in AOP.
Example of AOP
• Increased Maintainability.
• Increased Reusability
38
Terminology
• A join point is a well-defined point in the program flow
• A pointcut is a group of join points
• Advice is code that is executed at a pointcut
• Introduction modifies the members of a class and the relationships
between classes
• An aspect is a module for handling crosscutting concerns
• Aspects are defined in terms of pointcuts, advice, and introduction
• Aspects are reusable and inheritable
• Each of these terms will be discussed in greater detail
39
• AOP Concepts and Terminology
• AOP concepts and terminologies are as follows:
1. Join point
2. Advice
3. Pointcut
4. Target Object
5. Aspect
6. Weaving
AOP Concept:
•Join point: A join point is a specific point in the application where we can plug-in the
AOP aspect. Such as method execution, exception handling, etc. In Spring AOP, a join
point always represents a method execution.
•Pointcut: a predicate that matches join points. Advice is associated with a pointcut expression
and runs at any join point matched by the pointcut (for example, the execution of a method
with a certain name). The concept of join points as matched by pointcut expressions is central
to AOP, and Spring uses the AspectJ pointcut expression language by default.
• Advice:
• Action taken by an aspect at a particular join point.
• Different types of advice include "around," "before" and "after" advice.
Types of advice:
• Before advice: Advice that executes before a join point, but which does not have the ability to
prevent execution flow proceeding to the join point (unless it throws an exception).
• After returning advice: Advice to be executed after a join point completes normally: for example,
if a method returns without throwing an exception.
• After (finally) advice: Advice to be executed regardless of the means by which a join point exits
(normal or exceptional return).
• Around advice: Advice that surrounds a join point such as a method invocation. This is the most
powerful kind of advice. Around advice can perform custom behavior before and after the
method invocation..
Pointcut designator wildcards
• It is possible to use wildcards to declare pointcuts:
• execution(* *(..))
• Chooses the execution of any method regardless of return or parameter types
• call(* set(..))
• Chooses the call to any method named set regardless of return or parameter
type
• In case of overloading there may be more than one such set method; this
pointcut picks out calls to all of them
44
Pointcut designators based on types
• You can select elements based on types. For example,
• execution(int *())
• Chooses the execution of any method with no parameters that returns an int
• call(* setY(long))
• Chooses the call to any setY method that takes a long as an argument, regardless of
return type or declaring type
• call(* Point.setY(int))
• Chooses the call to any of Point’s setY methods that take an int as an argument,
regardless of return type
• call(*.new(int, int))
• Chooses the call to any classes’ constructor, so long as it takes exactly two ints as
arguments
45
Pointcut designator composition
• Pointcuts compose through the operations or (“||”), and (“&&”) and not (“!”)
• Examples:
• target(Point) && call(int *())
• Chooses any call to an int method with no arguments on an instance of Point, regardless of its
name
• call(* *(..)) && (within(Line) || within(Point))
• Chooses any call to any method where the call is made from the code in Point’s or Line’s type
declaration
• within(*) && execution(*.new(int))
• Chooses the execution of any constructor taking exactly one int argument, regardless of where
the call is made from
• !this(Point) && call(int *(..))
• Chooses any method call to an int method when the executing object is any type except Point
46
• Program in aspect which will use declare and Point.clone().
• aspect CloneablePoint {
•
declare soft: CloneNotSupportedException:
execution(Object clone());
•
Object Point.clone() { return super.clone(); }
}
• https://youtu.be/yhN1qjTrpY4
• https://youtu.be/QdyLsX0nG30
• https://www.slideserve.com/jane/introduction-to-aspect-oriented-programmin
g
• https://www.youtube.com/watch?v=POa6ZZKq79E