Abstract: Context. There is a trend in the software industry towards building systems that dynamically adapt their behavior in response to their surrounding environment, given the proliferation of various technological devices, such as notebooks, smartphones, and wearables, capable of capturing their execution context. Context-oriented Programming (COP) allows developers to use layer abstractions to adapt software behavior to the context. A layer is associated with a context and can be dynamically activated in direct response to gathered information from its surrounding execution environment. However, most existing layer activation mechanisms have been tailored specifically to address a particular concern; implying that developers need to tweak layer definitions in contortive ways or create new specialized activation mechanisms altogether if their specific needs are not supported. Objective. Complementing ideas to expressively declare activation mechanism models with interfaces that define conditionals of activation mechanisms modularly, this paper proposes an Expressive and Modular Activation mechanism, named EMA. Method. To propose EMA, we analyze existing activation mechanisms in COP regarding activation features and scope strategies. After, we propose the design of EMA and validate it with a case study discussion. Results. Using a concrete JavaScript implementation of EMA, named EMAjs, we can implement two Web applications: a smartphone application as an example to illustrate EMAjs in action, and an application of home automation to discuss and compare our proposal. Conclusion. Our proposed mechanism allows developers to instantiate different activation scope strategies and interfaces to decouple the declaration of activation mechanism conditionals from the base code.
Paper presentation: https://youtu.be/76RgVB6JihQ?si=-uylVc4Xnqnh4zbl
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
An expressive and modular layer activation mechanism for Context-Oriented Programming
1. Paul Leger, Universidad Católica del Norte, Chile
(pleger@ucn.cl / http://pleger.cl)
Nicolás Cardozo, Universidad de los Andes, Colombia
(n.cardozo@uniandes.edu.co)
Hidehiko Masuhara,Tokyo Institute of Technology, Japan
(masuhara@acm.org)
Journal First: Information & Software Technology (2023)
An Expressive and Modular Layer Activation
Mechanism for Context-Oriented Programming
9. CONTEXT-ORIENTED PROGRAMING (COP)
Portrait Landscape
Two different modes that are
activated when the phone is rotated
Phone is
rotated The landscape layer is activated
i.e., draw behavior is modified
Phone is
rotated
Layers (contexts)
These modes can be
contexts
time
4
11. ACTIVATION MECHANISMS
activate landscape if
(screen.angle > 45);
When a particular state
changes
(Lambic-2012)
Implicit
How is a layer activated?
When the screen angle
changes
5
12. ACTIVATION MECHANISMS
activate landscape if
(screen.angle > 45);
When a particular state
changes
(Lambic-2012)
Implicit
How is a layer activated?
When the screen angle
changes
NOTE: They are other activation mechanisms
5
14. WE CAN CURRENTLY OBSERVE AN IMPLICIT DEPENDENCY BETWEEN …
… base code and layers
(angle)
activate landscape if
(screen.angle > THRESHOLD);
Implicit
7
15. WE CAN CURRENTLY OBSERVE AN IMPLICIT DEPENDENCY BETWEEN …
… base code and layers
(angle)
So what ….
Problems in … Reuse? Evolution?
activate landscape if
(screen.angle > THRESHOLD);
Implicit
7
17. IMPLICIT DEPENDENCY PROBLEMS: REUSE
Smartphone Tablet
(a new scenario)
Layers
How about angles in other
format, even worse,
if it does not exist!
8
18. IMPLICIT DEPENDENCY PROBLEMS: EVOLUTION
Smartphone Layers
Base code changed
A layer needs to be modified to satisfy
the new requirements of base code
9
19. FIXED SCOPE STRATEGY FOR LAYERS
Most
Videogames
with landscape support
Layers
10
20. FIXED SCOPE STRATEGY FOR LAYERS
A layer needs a scope
to know where it should be applied or not
Most
Videogames
with landscape support
A videogame
that needs always
a portrait view
Layers
10
22. EMA: EXPRESSIVE AND MODULAR ACTIVATION
MECHANISM
Base
code
Interface Layer
EMA promotes the reuse of layers through:
1. separating layers and base code
2. customizing the scope to any layer deployment
exposes
Reads
12
23. EMA: EXPRESSIVE AND MODULAR ACTIVATION
MECHANISM
Base
code
Interface Layer
EMA promotes the reuse of layers through:
1. separating layers and base code
2. customizing the scope to any layer deployment
Explicit dependency
exposes
Reads
12
24. EMA: EXPRESSIVE AND MODULAR ACTIVATION
MECHANISM
Base
code
Interface Layer
EMA promotes the reuse of layers through:
1. separating layers and base code
2. customizing the scope to any layer deployment
Explicit dependency
Scope
Specific scope
strategy per Layer
Customizable scope
strategy per layer
exposes
Reads
12
25. SEPARATION OF LAYERS AND BASE CODE: REUSE
Smartphone Layers
Interface
13
rotation
26. SEPARATION OF LAYERS AND BASE CODE: REUSE
Smartphone Tablet
Layers
The interface can support
expressions which gives more
flexibility
Interface
Interface
13
rotation
27. SEPARATION OF LAYERS AND BASE CODE: EVOLUTION
Smartphone Layers
Developers can update the base
code without modifying the layer 14
rotation
28. SEPARATION OF LAYERS AND BASE CODE: EVOLUTION
Smartphone Tablet
Layers
Developers can update the base
code without modifying the layer
You can still reuse with a Tablet 14
rotation
29. ACTIVATION MECHANISMS: IMPERATIVE, EVENT-BASED, AND IMPLICIT
if (screen.angle > THRESHOLD) {
//applying layer on base code
with(landscape) {
playerView.draw();
}
}
Using a construct, a programmer
explicitly activates a layer
(ContextJ-2011)
Imperative
on(* playerView.draw()) &&
when(screen.angle > THRESHOLD){
with(landscape);
}
When specific some
events happen
(Jcop-2011)
Event-Based
activate landscape if
(screen.angle > THRESHOLD);
When a condition
changes
(Lambic-2011)
Implicit
How is a layer activated?
15
32. FLEXIBLE LAYER SCOPING
RotationCondition = () => rotation > THRESHOLD
Implicit
EMA.activate(allOf(RotationCondition))
EMA.activate(allOf(RotationCondition), screen)
EMA.activate(atMostOne(RotationCondition), Screen)
EMA Activation for a single object
instance, for all applicable objects
Activation for all objects of a class,
for at most one of the instances
that satisfy the condition
17
35. EMAjs:
A WORKING IMPLEMENTATION FOR JAVASCRIPT
JavaScript Object definitions
Layer is defined with
the activation condition
19
36. EMAjs:
A WORKING IMPLEMENTATION FOR JAVASCRIPT
JavaScript Object definitions
Layer is defined with
the activation condition
An object exposes their fields to
layers (as an Interface)
19
37. EMAjs:
A WORKING IMPLEMENTATION FOR JAVASCRIPT
JavaScript Object definitions
Layer is defined with
the activation condition
An object exposes their fields to
layers (as an Interface)
19
Developers define how the base
code should changed
40. A VALIDATION CASE: HOME AUTOMATION SYSTEM
Only ringing at
the room where the princess is
(COP) 20
41. A VALIDATION CASE: HOME AUTOMATION SYSTEM
BASE
COP
EMA
ADAPTATION ADAP. ADMIN
OOP
Only ringing at
the room where the princess is
(COP)
Using EMAjs, base code is more modular
than proposals with OOP and COP
20
45. RELATED WORK
Since 2005, we can find proposals related to COP
Most of them with fixed semantics for layer activations and scoping
22
First work for layer interfaces and customizable scope
47. CONCLUSION
• We propose Expressive and Modular Activation (EMA) mechanism for
Context-Oriented Programming (COP) to enhance the reuse of layers
• EMAjs is a WORKING implementation for JavaScript (on GitHub)
GitHub of EMAjs Paper
24
48. CONCLUSION
• We propose Expressive and Modular Activation (EMA) mechanism for
Context-Oriented Programming (COP) to enhance the reuse of layers
• EMAjs is a WORKING implementation for JavaScript (on GitHub)
GitHub of EMAjs Paper
24
49. @FLAGlab in all media channels
Journal of Information and Software Technology
Volume 156, April 2023
Programming language
implementations for context-oriented
self-adaptive systems
Paul Leger1 Nicolás Cardozo2 Hidehiko Masuhara3
1Systems and Computing Engineering department - Universidad católica del Norte, Coquimbo - Chile
2Systems and Computing Engineering department - Universidad de los Andes, Bogotá - Colombia
3Department of Mathematical and Computing Science - Tokyo Institute of Technology, Tokyo - Japan
pleger@ucn.cl, n.cardozo@uniandes.edu.co, masuhara@is.titech.ac.jp @ncardoz