SlideShare une entreprise Scribd logo
1  sur  263
Télécharger pour lire hors ligne
Lecture 08 :

Context-Oriented Programming

Overview and Applications
LSINF 2335
Programming Paradigms
Prof. Kim Mens
Dr. Sebastián González
UCL / EPL / INGI
Disclaimer: any pictures used in this presentation remain
with the copyright of their original owner and were
included here for didactical purposes only. In case of any
suspected violation of copyright please contact me so
that I can remove or replace those pictures.
Why?
… through a programming
language engineering approach
enable context-driven behaviour
adaptability …
Hardware Phenomena 3
fixed (1980)
mainframes

servers

desktops

consoles
portable (1990)
laptops

netbooks

subnotebooks
mobile (2000)
handhelds

tablets

smartphones
‣ CPU load
‣ available memory (RAM)
‣ available storage (HD)
‣ date and time
‣ connected peripherals
‣ network peers
‣ touch screen
‣ geographical location
‣ GPS signal quality
‣ accelerometer
‣ wi-fi signal quality
‣ battery power
‣ camera
‣ microphone
‣ light sensor
+
+
…
text (1970)
BSD

SunOS

MS DOS

GNU/Linux
graphical (1980)
Mac OS

Amiga OS

Windows

KDE, GNOME
web (1990)
static

dynamic

web 2.0

mashups
mobile (2000)
Symbian OS

Windows CE

iOS

Android
Software Phenomena 4
‣ available libraries
‣ available hardware services
‣ available network services
‣ user task
‣ user expertise
‣ user preferences
‣ user privileges
‣ task urgency
‣ operation modes
‣ logging
‣ debugging
‣ degraded
‣ free trial
‣ partial failure
‣ domain specific
‣ [3D] wireframe / solid view
‣ [Maps] satellite / schematic
‣ ...
Applications should be aware of their execution context, and
should adapt dynamically to such context so that they can provide
a service that matches client needs to the best extent possible.
environmental properties
humidity, light, noise, lighting
network peers & services
projector, GPS, storage
internal state
load, time, battery
spatial state
position, orientation,
movement
location semantics
nearby objects & facilities
users
expertise, preferences
Context Is Key 5
take advantage of room projector for presentation
peer service
decrease playback quality when battery power is low
internal state
user task
show parking spots and gas stations (only) when driving
environmental conditions
give more detailed indications when visibility is low
disable phone ringtone in quiet places
location semantics
Adaptation Examples 6
Why Aren’t We There Yet? 7
Richard Gabriel, 2006
Software systems today are produced according to a
manufacturing model: a finished product is constructed
at the factory and shipped to its final destination where
it is expected to act like any other machine —reliable
but oblivious to its surroundings and its own welfare.
we still program this...
using the
programming models
conceived for this....
(2010) (1980)
Mindset Mismatch 8
Current programming techniques and design principles invite
programmers to think in a way that is mostly oblivious of the physical,
technical and human environment in which the software will be used.
Many chances of delivering improved services are thus missed.
programming in isolation
?
?
?
?
?
?
Current Mindset 9
programming with context
A new paradigm is needed that helps overcoming this limiting vision
by putting programmers in the right state of mind to build
dynamically adaptable applications from the ground up.
Needed Mindset 10
programming in isolation programming with context
forward!
?
?
?
?
?
?
Towards A Mindset Shift 11
Conditional statementsDesign patternsPlugin architectures
programming in isolation programming with context
forward!
?
?
?
?
?
?
Towards A Mindset Shift 11
Adaptation Example 12
context behaviour
ringtonedefault
call reception behaviour
Adaptation Example 12
context behaviour
vibrationquiet
call reception behaviour
Adaptation Example 12
off-hook call waiting signal
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Adaptation Example 12
unavailable forward call
context behaviour
call reception behaviour
Paradigmatic Shortcomings 13
class phone {



method receive ( call ) {



if ( phone.isOffHook( ) )

play( phone.callWaitingSignal( ), 2 );



else if ( phone.environment( ).acoustics( ).isQuiet( ) )

phone.vibrate( 5 );



else if ( phone.user( ).isUnavailable( ) )

forwardCall( call, phone.forwardNumber( ) );



else

play( phone.ringTone( ), 10 );

}
conditional statements
class phone {

method receive ( call ) {

if ( ) then

else if ( ) then

else if ( ) then

else

}
Paradigmatic Shortcomings 14
conditional statements
class phone {

method receive ( call ) {

if ( ) then

else if ( ) then

else if ( ) then

else

}
Paradigmatic Shortcomings 14
conditional statements
Adaptable
default
phone user
phone environment
phone status
class phone {

method receive ( call ) {

if ( ) then

else if ( ) then

else if ( ) then

else

}
Paradigmatic Shortcomings 14
conditional statements
Adaptable
default
phone user
phone environment
phone status
class phone {

method receive ( call ) {

if ( ) then

else if ( ) then

else if ( ) then

else

}
Paradigmatic Shortcomings 14
conditional statements
Adaptable
Tangled
Scattered
Fixed
No reuse
Complex logic
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
special software architectures
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Modular
Open
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Modular
Open
Infrastructural burden
Anticipated adaptation points
Paradigmatic Shortcomings 15
class Phone

{ attribute strategy;
method receive ( call )

{ strategy.receive( call ); } }
class UnavailableStrategy

{ method receive ( call ) { ... } }
class OffHookStrategy

{ method receive ( call ) { ... } }
class QuietStrategy

{ method receive ( call ) { ... } }
class DefaultStrategy

{ method receive ( call ) { ... } }
Phone
QuietStrategy
OffHookStrategy
UnavailableStrateg
DefaultStrategy
strategy.receive( call );
special software architectures
Modular
Open
Infrastructural burden
Anticipated adaptation points
Paradigmatic Shortcomings 16
Software rigidness

The variability points of the application are hard-
coded in its architecture. It is difficult to add new
variants non-invasively.

Lack of modularity

Tight coupling between core business logic and
infrastructural code to manage the variants makes the
software difficult to maintain and evolve.

Mindset mismatch

Programming tools make programmers oblivious of
the context in which their applications will run.
Programmers are not put in the right state of mind to
build adaptable software.
General Symptoms (Recap)
Hypothesis 17
current programming tools
adaptive systems
we need to reengineer our tools
A major obstacle for adaptability is the unavailability of appropriate
context-aware programming languages and related tool sets.
Approach 18
programming abstractions matter
tool 1: C#
using System;
public class Program
{
static long Factorial(long number)
{
if(number <= 1)
return 1;
else
return number * Factorial(number - 1);
}
static int Main(string[] args) {
Console.WriteLine(Factorial(5));
return 0;
}
}
tool 2: Ruby
def fact(n)
n <= 1 ? 1 : n * fact(n - 1)
end
fact(5)
n! =
{
1
n(n-1)!
if n = 0
if n > 0
maintainability
domain: math
Approach
A high-level language frees a program from
much of its accidental complexity; it eliminates
a whole level of complexity that was never
inherent in the program at all.
programming language engineering
19
Develop programming tools that reduce accidental complexity
in the expression of context-driven behaviour adaptation
Frederick Brooks, 1987
essential complexity ≠
accidental complexity
Subjective-C
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Ambience
2008 20132011
Context Traits
Subjective-C
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Ambience
2008 20132011
Context Traits
Subjective-C
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Bringing Context to
Mobile Platform Programming
Context-Driven System Architecture 21
external context
effect
context
information
ActuatorsSensors
arbitrated

context
changes
World
Context
Discovery
Context
Management
Active
Context
internal
Application
Behaviour
Contexts As Situation Reifiers 22
computationally
accessible data
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
Contexts As Situation Reifiers 22
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
Contexts As Situation Reifiers 22
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
Low battery charge
High CPU load
Firefox
Landscape orientation
Contexts As Situation Reifiers 22
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
contexts are reified situations
for which adapted application behaviour can be defined
Low battery charge
High CPU load
Firefox
Landscape orientation
Contexts As Situation Reifiers 22
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
contexts are reified situations
for which adapted application behaviour can be defined
Low battery charge
High CPU load
Firefox
Landscape orientation
LowBattery = new Context();
window.addEventListener(‘batterystatus’,
function (battery) {
if (battery.level < 30)
LowBattery.activate();
else
LowBattery.deactivate(); });
… in JavaScript
Contexts As Situation Reifiers 22
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
contexts are reified situations
for which adapted application behaviour can be defined
Low battery charge
High CPU load
Firefox
Landscape orientation
LowBattery = new Context();
window.addEventListener(‘batterystatus’,
function (battery) {
if (battery.level < 30)
LowBattery.activate();
else
LowBattery.deactivate(); });
… in JavaScript
23
Label
Minimalistic Case Study
Standard Widget Spec
UILabel class
drawTextInRect:
Draws the receiver’s text in the specified rectangle.
- (void)drawTextInRect:(CGRect)rect
Parameters
rect
The rectangle in which to draw the text.
Discussion
You should not call this method directly. This method
should only be overridden by subclasses that want to
modify the default drawing behavior for the label’s text.
Availability
Available in iOS 2.0 and later.
Declared In
UILabel.h
24
Main Idea 25
@implementation UILabel (color)
@contexts Landscape
- (void)drawTextInRect:(CGRect)rect {
self.textColor = [UIColor greenColor];
return @resend();
}
@end
Application
Behaviour
Main Idea 25
@implementation UILabel (color)
@contexts Landscape
- (void)drawTextInRect:(CGRect)rect {
self.textColor = [UIColor greenColor];
return @resend();
}
@end
Application
Behaviour
Label
Main Idea 25
@implementation UILabel (color)
@contexts Landscape
- (void)drawTextInRect:(CGRect)rect {
self.textColor = [UIColor greenColor];
return @resend();
}
@end
Application
Behaviour
Main Idea 25
@implementation UILabel (color)
@contexts Landscape
- (void)drawTextInRect:(CGRect)rect {
self.textColor = [UIColor greenColor];
return @resend();
}
@end
Open classes
Objective-C
COP
Subjective-C
Application
Behaviour
Main Idea 25
@implementation UILabel (color)
@contexts Landscape
- (void)drawTextInRect:(CGRect)rect {
self.textColor = [UIColor greenColor];
return @resend();
}
@end
Open classes
Objective-C
COP
Subjective-C
✓ Adaptation of any existing component

✓ No access to original source code needed

✓ Adaptations can be cleanly modularised
Application
Behaviour
Context Relations
Implication Antwerp Belgium Antwerp => Belgium
Suggestion ClassRoom Quiet ClassRoom -> Quiet
Requirement HDVideo BatteryHigh HDVideo =< BatteryHigh
Exclusion Landscape Portrait Landscape >< Portrait
26
Context
Management
Combination Driving + UKDriving+UK
Driving
UK
Avoiding Boilerplate 27
// Create contexts
Context* Room = [[Context alloc] initWithName:@"Room"];
Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];
Context* Day = [[Context alloc] initWithName:@"Day"];
Context* Night = [[Context alloc] initWithName:@"Night"];
…
// Register contexts
[CONTEXT addContext:Room];
[CONTEXT addContext:Bedroom];
[CONTEXT addContext:Day];
[CONTEXT addContext:Night];
…
// Establish context relations
[Day addExclusionRelationWith:Night];
[Bedroom addHardInclusionRelationWith:Room];
…
// Register context-specific methods
[MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom)
forClass:[DomoticsServerViewController class]
forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil]
withDefautSel:@selector(getActiveRoom)
withPriority:0];
…
Avoiding Boilerplate 27
// Create contexts
Context* Room = [[Context alloc] initWithName:@"Room"];
Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"];
Context* Day = [[Context alloc] initWithName:@"Day"];
Context* Night = [[Context alloc] initWithName:@"Night"];
…
// Register contexts
[CONTEXT addContext:Room];
[CONTEXT addContext:Bedroom];
[CONTEXT addContext:Day];
[CONTEXT addContext:Night];
…
// Establish context relations
[Day addExclusionRelationWith:Night];
[Bedroom addHardInclusionRelationWith:Room];
…
// Register context-specific methods
[MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom)
forClass:[DomoticsServerViewController class]
forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil]
withDefautSel:@selector(getActiveRoom)
withPriority:0];
…
Relations:
Day >< Night
Sun >< Rain
Livingroom -> TV
Livingroom -> Window
Livingroom -> Luminosity
Livingroom -> Temperature
Kitchen -> Luminosity
Bedroom -> Temperature
Bedroom -> Luminosity
Bedroom -> Window
Bathroom -> Temperature
Bathroom -> Luminosity
Bathroom => Room
Kitchen => Room
Livingroom => Room
Bedroom => Room
TV =< Electricity
Luminosity =< Electricity
Window =< Sun
Contexts:
Room
Livingroom
Kitchen
Bedroom
Bathroom
Day
Night
TV
Window
Temperature
Luminosity
Sun
Rain
Electricity
@implementation LowpassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = filterConstant;
if(adaptive)
alpha = ... // big formula to calculate the alpha level
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
-(NSString*)name
{
return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter";
}
...
Case Study: Hard-Coded Operation Mode 28
@implementation LowpassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = filterConstant;
if(adaptive)
alpha = ... // big formula to calculate the alpha level
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
-(NSString*)name
{
return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter";
}
...
Case Study: Hard-Coded Operation Mode 28
@implementation LowpassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = filterConstant;
if(adaptive)
alpha = ... // big formula to calculate the alpha level
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
-(NSString*)name
{
return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter";
}
...
Case Study: Hard-Coded Operation Mode 28
Operation mode (intrinsic context)Adaptive
Case Study: Refactoring Using Logical Contexts 29
@implementation LowpassFilter
@contexts LowPassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = [self getAlpha:accel];
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
@contexts !Adaptive
-(double) getAlpha:(UIAcceleration*)accel{
return filterConstant;
}
@contexts Adaptive LowPassFilter
-(double) getAlpha:(UIAcceleration*)accel {
return // big formula to calculate the alpha level;
}
Adaptive
Adaptive
Case Study: Refactoring Using Logical Contexts 29
@implementation LowpassFilter
@contexts LowPassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = [self getAlpha:accel];
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
@contexts !Adaptive
-(double) getAlpha:(UIAcceleration*)accel{
return filterConstant;
}
@contexts Adaptive LowPassFilter
-(double) getAlpha:(UIAcceleration*)accel {
return // big formula to calculate the alpha level;
}
Case Study: Refactoring Using Logical Contexts 29
@implementation LowpassFilter
@contexts LowPassFilter
-(void)addAcceleration:(UIAcceleration*)accel
{
double alpha = [self getAlpha:accel];
x = accel.x * alpha + x * (1.0 - alpha);
y = accel.y * alpha + y * (1.0 - alpha);
z = accel.z * alpha + z * (1.0 - alpha);
}
@contexts !Adaptive
-(double) getAlpha:(UIAcceleration*)accel{
return filterConstant;
}
@contexts Adaptive LowPassFilter
-(double) getAlpha:(UIAcceleration*)accel {
return // big formula to calculate the alpha level;
}
Relations:
LowPassFilter >< HighPassFilter
LowPassFilter => Filter
HighPassFilter => Filter
Contexts:
Adaptive
Paused
LowPassFilter
HighPassFilter
Filter
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-agnostic
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-specific
domain-agnostic
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-specific
domain-agnostic
extrinsic
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-specific
intrinsic
domain-agnostic
extrinsic
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-specific
intrinsic
domain-agnostic
extrinsic
physical
Logging
Context Scoping 30
Local contexts
Global contexts
Landscape
LowBattery
BusyCPU
Antwerp
• Affect all threads

@activate(LowBattery)
• Usually domain-agnostic

– extrinsic to the application

– based on physical phenomena

• Activation follows external events
• Local to one thread

@activate(Adaptive in Thread1)
• Usually domain-specific

– intrinsic to the application

– based on logical events

• Activation follows business logic
Adaptive
Off-Hook
HDVideo
domain-specific
intrinsic
logical
domain-agnostic
extrinsic
physical
Summary 31
✓ Clean application logic

✓ Clean modularisation of adaptations

✓ Context reification and management

✓ Run-time behaviour adaptation of any component (incl. 3rd party)

✓ No need for recompilation or access to original source code

✓ Maximises adaptation points while avoiding architectural burden

✓ Scoped adaptations
language abstractions for adaptation to context … with sound technical underpinnings
@context Landscape
-id behaviour {
// context-specific logic
}
Objects
Open Classes
Reflection
Subjective Programming
Context-Oriented Programming
Subjective-C
Subjective-C
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Ambience
2008 20132011
Context Traits
Subjective-C
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Ambience
2008 20132011
Context Traits
What?
context-driven

software adaptability through
dedicated language abstractions
and composition mechanisms
Dynamic Behaviour Adaptation Through
Run-Time Trait Recomposition
Context Traits
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
provided
methods
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
required
methods
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
sum
operator
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
=
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
=
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
traits.js [ Van Cutsem &
Miller 2011 ]
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
Traits As Basic Behavioural Units 33
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Traits As Basic Behavioural Units 33
+
+
tag a1=”v1” a2=”v2”
T.Element
elementsByTagName
elementsByAttribute
getAttribute
setAttribute
walkChildren
T.Element =
Trait({
elementsByTagName: function(name) { ... },
elementsByAttribute: function(attr) { ... },
getAttribute: Trait.required,
setAttribute: Trait.required,
walkChildren: Trait.required });
... in JavaScript
=
T.Tag
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
T.Node
content
parent
appendChild
replaceChild
removeChild
walkChildren
XML.Element
tagName
addAttribute
getAttribute
setAttribute
removeAttribute
forEachAttribute
content
parent
appendChild
replaceChild
removeChild
walkChildren
id
elementsByTagName
elementsByAttribute
Default Behaviour & Context 34
HTML.Element
addAttribute
getAttribute
...
style
title
T.HTML.Element
class
style
title
getAttribute
setAttribute
= XML.Element +
Default Behaviour & Context 34
= HTML.Element +
HTML.Anchor
addAttribute
...
href
type
target
T.HTML.Anchor
href
type
target
getAttribute
setAttribute
HTML.Element
addAttribute
getAttribute
...
style
title
T.HTML.Element
class
style
title
getAttribute
setAttribute
= XML.Element +
Default Behaviour & Context 34
= HTML.Element +
HTML.Anchor
addAttribute
...
href
type
target
T.HTML.Anchor
href
type
target
getAttribute
setAttribute
HTML.Element
addAttribute
getAttribute
...
style
title
T.HTML.Element
class
style
title
getAttribute
setAttribute
= XML.Element +
HTML.Element =
Trait.compose(XML.Element, T.HTML.Element);
HTML.Anchor =
Trait.compose(HTML.Element, T.HTML.Anchor);
... in JavaScript
Default Behaviour & Context 34
= HTML.Element +
HTML.Anchor
addAttribute
...
href
type
target
T.HTML.Anchor
href
type
target
getAttribute
setAttribute
Default
... for prototypical situations
Prototypical behaviour ...
HTML.Element
addAttribute
getAttribute
...
style
title
T.HTML.Element
class
style
title
getAttribute
setAttribute
= XML.Element +
( unperturbed system )
HTML.Element =
Trait.compose(XML.Element, T.HTML.Element);
HTML.Anchor =
Trait.compose(HTML.Element, T.HTML.Anchor);
... in JavaScript
Default Behaviour & Context 34
= HTML.Element +
HTML.Anchor
addAttribute
...
href
type
target
T.HTML.Anchor
href
type
target
getAttribute
setAttribute
Default
... for prototypical situations
Prototypical behaviour ...
HTML.Element
addAttribute
getAttribute
...
style
title
T.HTML.Element
class
style
title
getAttribute
setAttribute
= XML.Element +
( unperturbed system )
HTML.Element =
Trait.compose(XML.Element, T.HTML.Element);
HTML.Anchor =
Trait.compose(HTML.Element, T.HTML.Anchor);
... in JavaScript
Context + Traits 35
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
Context + Traits 35
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
Context + Traits 35
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
Context + Traits 35
W3Clet W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
Context + Traits 35
W3Clet W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
Context + Traits 35
W3Clet W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
Context + Traits 35
W3Clet W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Context + Traits 35
W3Clet W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Context + Traits 35
W3C
constitution
( ida, Untrusted ) =
Untrusted.adapt

(a, T.SecureAnchor);
let W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
T.SecureAnchor
href
parent
visible
manager
...
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Context + Traits 35
W3C
constitution
( ida, Untrusted ) =
Untrusted.adapt

(a, T.SecureAnchor);
let W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
T.SecureAnchor
href
parent
visible
manager
...
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Context + Traits 35
W3C
constitution
( ida, Untrusted ) =
Untrusted.adapt

(a, T.SecureAnchor);
let W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
T.SecureAnchor
href
parent
visible
manager
...
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Context + Traits 35
W3C
constitution
( ida, Untrusted ) =
Untrusted.adapt

(a, T.SecureAnchor);
let W3C ∈ C W3C = new Context();
... in JavaScriptContext Traits
T.SecureAnchor
href
parent
visible
manager
...
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
Run-Time Trait Recomposition 36
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
Run-Time Trait Recomposition 36
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
HTML.Anchor
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.SecureAnchor
href
parent
visible
manager
...
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
▹ ▹
overriding operator
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
HTML.Anchor
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.SecureAnchor
href
parent
visible
manager
...
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
▹ ▹
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Run-Time Trait Recomposition 36
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T
defined through composition policiescomposition: 2T → O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
o = TC1 · TC2 · ... · TCn
puts object composition in direct relationship
to the context of execution
object: L ⨉ 2C → O
object = composition · constitution
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
Context-Driven Trait Composition 37
TD
T
T
T
TT
Context-Driven Trait Composition 37
TD
T
T
T
TT
Context-Driven Trait Composition 37
TD
T
T
T
T
T
Context-Driven Trait Composition 37
TD
T
T
T
T
T
Context-Driven Trait Composition 37
TD
T T
T
T
T
Context-Driven Trait Composition 37
TD
T T
T
T
T
Context-Driven Trait Composition 37
TD
T T
T
T
T
Context-Driven Trait Composition 37
TD
T T
T
T
T
Context-Driven Trait Composition 37
TD
T T
T
T
T
Composition Policies 38
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
Composition Policies 38
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
Composition Policies 38
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Composition Policies 38
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
exclusion operator
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
P : 2T → 2T
P = Povr · Pbysec
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
✓Arbitrary combinations
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
P : 2T → 2T
P = Povr · Pbysec
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
✓Arbitrary combinations
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
P : 2T → 2T
P = Povr · Pbysec
Composition Policies 38
Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor }
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parent
visible
addAttribute
setAttribute
removeAttribute
parent
=
✓Arbitrary combinations
HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹
o
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
addAttribute
setAttribute
removeAttribute
href
parent
visible
type
target
href
parentparent
addAttribute
setAttribute
removeAttribute
What if we want to
bypass security of
visible?
✗ Impossible with strict overriding semantics
(e.g. inheritance, mixins, COP layers)
Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) =
{ }
P : 2T → 2T
P = Povr · Pbysec
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
HTML.Anchor
...
setAttribute
...
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
HTML.Anchor
...
setAttribute
...
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
HTML.Anchor
...
setAttribute
...
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
aliasing operator
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
...becomes requirement
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
how to invoke overridden behaviour?
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Behaviour Extensibility Challenge 39
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
T.ValidAnchor.setAttribute = function(name, value) {
...
return self.htmlSetAttribute(name, value);
}
T.ValidAnchor’
addAttribute
setAttribute
removeAttribute
parent
htmlSetAttribute
...
HTML.Anchor
...
setAttribute
...
[ htmlSetAttribute ↦ setAttribute ] =
HTML.Anchor’
...
setAttribute
htmlSetAttribute
...
→ manual edition →
▹
✗ bypassed T.SecureAnchor
▹▹
✗ hard-coded choice of
overridden behaviour
Extensibility Through Proceed 40
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
proceed
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
becomes requirement
how to invoke overridden behaviour?
proceed
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
proceed
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
✓ open choice of
overridden behaviour
how to invoke overridden behaviour?
proceed
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
proceed
▹
T.SecureAnchor
...
setAttribute
...
parent
visible
manager
...
▹
Extensibility Through Proceed 40
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
proceed
▹
T.SecureAnchor
...
setAttribute
...
parent
visible
manager
...
▹
Extensibility Through Proceed 40
T.Extensible
proceed
Dynamic
T.ValidAnchor = Trait({
setAttribute: function(name, value) {
... // validity check
return self.proceed();
},
...
});
HTML.Anchor
...
setAttribute
...
T.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
how to invoke overridden behaviour?
proceed
▹
T.SecureAnchor
...
setAttribute
...
parent
visible
manager
...
▹
Summary 41
✓ Contexts: frame of reference to define adaptations

✓ Traits: convenient units of adaptation

✓ Policies: flexible compositions (e.g. non-linear)

✓ Extensibility: independent behaviour extensions

✓ JavaScript: easy definition of contexts, traits, and composition
direct causal connection
composition of the computational system
situation in which the system executes
⇋
Context Traits
How?
Subjective-CAmbience
2008 20132011
Context Traits
implementation of context-driven

software adaptability through …
… method dispatch … and method pre-dispatch.
Method Pre-Dispatch 43
When a context is (de)activated,

for every class and selector the context adapts, find
all active methods

M(c, s)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and deploy the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
Method Pre-Dispatch 43
When a context is (de)activated,

for every class and selector the context adapts, find
all active methods

M(c, s)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and deploy the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
deploy
Method Pre-Dispatch 43
When a context is (de)activated,

for every class and selector the context adapts, find
all active methods

M(c, s)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and deploy the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
structural reflection
deploy
Method Dispatch 44
When a message is received,

find all applicable methods for the given message
(with receiver r, selector s and arguments a)

M(r,s,a)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and invoke the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
Method Dispatch 44
When a message is received,

find all applicable methods for the given message
(with receiver r, selector s and arguments a)

M(r,s,a)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and invoke the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
message is received
Method Dispatch 44
When a message is received,

find all applicable methods for the given message
(with receiver r, selector s and arguments a)

M(r,s,a)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and invoke the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
invoke
message is received
Method Dispatch 44
When a message is received,

find all applicable methods for the given message
(with receiver r, selector s and arguments a)

M(r,s,a)={ m1, m2, m3, ..., mn }
reorder them according to specificity

m1 < m2 < m3 < ... < mn
and invoke the first one

m1

‣m1 is the most specific implementation for the current context

‣ resend invokes the remaining methods in order

‣mn is (usually) the default implementation
[ behavioural reflection ]
invoke
message is received
Method Pre-Dispatch 45
Is the method order always defined?
• Could there be no applicable methods?

➡ default implementation

• Could there be non-comparable methods?

➡ the order should be total

➡ if not, we’re in trouble
M(r,s,a)={ m1, m2, m3, ..., mn }
M(c, s)={ m1, m2, m3, ..., mn }
Method Pre-Dispatch 46
Subjective-C
Case Study
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect
 Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect
 Default impl
Landscape impl
Portrait impl
vtable
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect
 Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect
 Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

@activate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

@activate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

‣ no additional cost for method invocations

‣ cost incurred at context switching time
@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

‣ no additional cost for method invocations

‣ cost incurred at context switching time
@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

‣ no additional cost for method invocations

‣ cost incurred at context switching time
@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Subjective-C
Dynamic Method Pre-Dispatch 47
UILabel

@property NSString *text

@property UIFont *font

...

- (void)Portrait_drawTextInRect:(CGRect)rect

- (void)Landscape_drawTextInRect:(CGRect)rect

- (void)Default_drawTextInRect:(CGRect)rect

- (void)drawTextInRect:(CGRect)rect

‣ no additional cost for method invocations

‣ cost incurred at context switching time
@activate(Landscape);
@deactivate(Landscape);
Default impl
Landscape impl
Portrait impl
(1.0)
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming
Context-oriented programming

Contenu connexe

Similaire à Context-oriented programming

Ambience In A Nutshell
Ambience In A NutshellAmbience In A Nutshell
Ambience In A Nutshellkim.mens
 
Implementing 5S Concept In Warehouse Management
Implementing 5S Concept In Warehouse ManagementImplementing 5S Concept In Warehouse Management
Implementing 5S Concept In Warehouse ManagementLori Bowie
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоGeeksLab Odessa
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)Oleg Zinchenko
 
An introduction to Machine Learning
An introduction to Machine LearningAn introduction to Machine Learning
An introduction to Machine LearningValéry BERNARD
 
Ten^H^H^H Many Cloud App Design Patterns
Ten^H^H^H Many Cloud App Design PatternsTen^H^H^H Many Cloud App Design Patterns
Ten^H^H^H Many Cloud App Design PatternsShlomo Swidler
 
Introduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventureIntroduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventuremylittleadventure
 
Assembler & z/OS Internals Syllabus
Assembler & z/OS Internals SyllabusAssembler & z/OS Internals Syllabus
Assembler & z/OS Internals SyllabusDeru Sudibyo
 
Try the monad!
Try the monad!Try the monad!
Try the monad!Luis Muniz
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Garth Gilmour
 
Kapil_Resume
Kapil_ResumeKapil_Resume
Kapil_ResumeKapil Deb
 
Open source mobile development solutions
Open source mobile development solutionsOpen source mobile development solutions
Open source mobile development solutionsDaniel Downs
 
SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!melbats
 
Build, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at ScaleBuild, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at ScaleAmazon Web Services
 
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceWhat is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceGeoffrey De Smet
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 

Similaire à Context-oriented programming (20)

Anti Object-Oriented Design Patterns
Anti Object-Oriented Design PatternsAnti Object-Oriented Design Patterns
Anti Object-Oriented Design Patterns
 
Best practices android_2010
Best practices android_2010Best practices android_2010
Best practices android_2010
 
updated resumee
updated resumeeupdated resumee
updated resumee
 
Ambience In A Nutshell
Ambience In A NutshellAmbience In A Nutshell
Ambience In A Nutshell
 
Implementing 5S Concept In Warehouse Management
Implementing 5S Concept In Warehouse ManagementImplementing 5S Concept In Warehouse Management
Implementing 5S Concept In Warehouse Management
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
 
An introduction to Machine Learning
An introduction to Machine LearningAn introduction to Machine Learning
An introduction to Machine Learning
 
Ten^H^H^H Many Cloud App Design Patterns
Ten^H^H^H Many Cloud App Design PatternsTen^H^H^H Many Cloud App Design Patterns
Ten^H^H^H Many Cloud App Design Patterns
 
Good++
Good++Good++
Good++
 
Introduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventureIntroduction Machine Learning by MyLittleAdventure
Introduction Machine Learning by MyLittleAdventure
 
Assembler & z/OS Internals Syllabus
Assembler & z/OS Internals SyllabusAssembler & z/OS Internals Syllabus
Assembler & z/OS Internals Syllabus
 
Try the monad!
Try the monad!Try the monad!
Try the monad!
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
 
Kapil_Resume
Kapil_ResumeKapil_Resume
Kapil_Resume
 
Open source mobile development solutions
Open source mobile development solutionsOpen source mobile development solutions
Open source mobile development solutions
 
SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!
 
Build, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at ScaleBuild, Train, and Deploy ML Models at Scale
Build, Train, and Deploy ML Models at Scale
 
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev ConferenceWhat is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 

Plus de kim.mens

Software Maintenance and Evolution
Software Maintenance and EvolutionSoftware Maintenance and Evolution
Software Maintenance and Evolutionkim.mens
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristicskim.mens
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworkskim.mens
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflectionkim.mens
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Javakim.mens
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Rubykim.mens
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflectionkim.mens
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...kim.mens
 
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)kim.mens
 
Usage contracts in a nutshell
Usage contracts in a nutshellUsage contracts in a nutshell
Usage contracts in a nutshellkim.mens
 
INGI2252 Software Measures & Maintenance
INGI2252 Software Measures & MaintenanceINGI2252 Software Measures & Maintenance
INGI2252 Software Measures & Maintenancekim.mens
 
Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developerskim.mens
 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)kim.mens
 
Active Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVEActive Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVEkim.mens
 
Mining source code for structural regularities (SATTOSE2010)
Mining source code for structural regularities (SATTOSE2010)Mining source code for structural regularities (SATTOSE2010)
Mining source code for structural regularities (SATTOSE2010)kim.mens
 

Plus de kim.mens (20)

Software Maintenance and Evolution
Software Maintenance and EvolutionSoftware Maintenance and Evolution
Software Maintenance and Evolution
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristics
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworks
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflection
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Ruby
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflection
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...
 
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
Usage contracts (presented at SATToSE 2014 in L'Aquila, Italy)
 
Usage contracts in a nutshell
Usage contracts in a nutshellUsage contracts in a nutshell
Usage contracts in a nutshell
 
INGI2252 Software Measures & Maintenance
INGI2252 Software Measures & MaintenanceINGI2252 Software Measures & Maintenance
INGI2252 Software Measures & Maintenance
 
Building an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developersBuilding an Eclipse plugin to recommend changes to developers
Building an Eclipse plugin to recommend changes to developers
 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)
 
Active Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVEActive Software Documentation using Soul and IntensiVE
Active Software Documentation using Soul and IntensiVE
 
Mining source code for structural regularities (SATTOSE2010)
Mining source code for structural regularities (SATTOSE2010)Mining source code for structural regularities (SATTOSE2010)
Mining source code for structural regularities (SATTOSE2010)
 

Dernier

Pests of ragi_Identification, Binomics_Dr.UPR
Pests of ragi_Identification, Binomics_Dr.UPRPests of ragi_Identification, Binomics_Dr.UPR
Pests of ragi_Identification, Binomics_Dr.UPRPirithiRaju
 
Identification of Superclusters and Their Properties in the Sloan Digital Sky...
Identification of Superclusters and Their Properties in the Sloan Digital Sky...Identification of Superclusters and Their Properties in the Sloan Digital Sky...
Identification of Superclusters and Their Properties in the Sloan Digital Sky...Sérgio Sacani
 
MARSILEA notes in detail for II year Botany.ppt
MARSILEA  notes in detail for II year Botany.pptMARSILEA  notes in detail for II year Botany.ppt
MARSILEA notes in detail for II year Botany.pptaigil2
 
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...Sérgio Sacani
 
World Water Day 22 March 2024 - kiyorndlab
World Water Day 22 March 2024 - kiyorndlabWorld Water Day 22 March 2024 - kiyorndlab
World Water Day 22 March 2024 - kiyorndlabkiyorndlab
 
geometric quantization on coadjoint orbits
geometric quantization on coadjoint orbitsgeometric quantization on coadjoint orbits
geometric quantization on coadjoint orbitsHassan Jolany
 
Principles & Formulation of Hair Care Products
Principles & Formulation of Hair Care  ProductsPrinciples & Formulation of Hair Care  Products
Principles & Formulation of Hair Care Productspurwaborkar@gmail.com
 
Controlling Parameters of Carbonate platform Environment
Controlling Parameters of Carbonate platform EnvironmentControlling Parameters of Carbonate platform Environment
Controlling Parameters of Carbonate platform EnvironmentRahulVishwakarma71547
 
Applied Biochemistry feedback_M Ahwad 2023.docx
Applied Biochemistry feedback_M Ahwad 2023.docxApplied Biochemistry feedback_M Ahwad 2023.docx
Applied Biochemistry feedback_M Ahwad 2023.docxmarwaahmad357
 
Alternative system of medicine herbal drug technology syllabus
Alternative system of medicine herbal drug technology syllabusAlternative system of medicine herbal drug technology syllabus
Alternative system of medicine herbal drug technology syllabusPradnya Wadekar
 
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...marwaahmad357
 
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptx
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptxSCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptx
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptxROVELYNEDELUNA3
 
PSP3 employability assessment form .docx
PSP3 employability assessment form .docxPSP3 employability assessment form .docx
PSP3 employability assessment form .docxmarwaahmad357
 
Role of Herbs in Cosmetics in Cosmetic Science.
Role of Herbs in Cosmetics in Cosmetic Science.Role of Herbs in Cosmetics in Cosmetic Science.
Role of Herbs in Cosmetics in Cosmetic Science.ShwetaHattimare
 
Main Exam Applied biochemistry final year
Main Exam Applied biochemistry final yearMain Exam Applied biochemistry final year
Main Exam Applied biochemistry final yearmarwaahmad357
 
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdf
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdfSUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdf
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdfsantiagojoderickdoma
 
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...Sérgio Sacani
 
Gene transfer in plants agrobacterium.pdf
Gene transfer in plants agrobacterium.pdfGene transfer in plants agrobacterium.pdf
Gene transfer in plants agrobacterium.pdfNetHelix
 
Physics Serway Jewett 6th edition for Scientists and Engineers
Physics Serway Jewett 6th edition for Scientists and EngineersPhysics Serway Jewett 6th edition for Scientists and Engineers
Physics Serway Jewett 6th edition for Scientists and EngineersAndreaLucarelli
 

Dernier (20)

Pests of ragi_Identification, Binomics_Dr.UPR
Pests of ragi_Identification, Binomics_Dr.UPRPests of ragi_Identification, Binomics_Dr.UPR
Pests of ragi_Identification, Binomics_Dr.UPR
 
Identification of Superclusters and Their Properties in the Sloan Digital Sky...
Identification of Superclusters and Their Properties in the Sloan Digital Sky...Identification of Superclusters and Their Properties in the Sloan Digital Sky...
Identification of Superclusters and Their Properties in the Sloan Digital Sky...
 
Data delivery from the US-EPA Center for Computational Toxicology and Exposur...
Data delivery from the US-EPA Center for Computational Toxicology and Exposur...Data delivery from the US-EPA Center for Computational Toxicology and Exposur...
Data delivery from the US-EPA Center for Computational Toxicology and Exposur...
 
MARSILEA notes in detail for II year Botany.ppt
MARSILEA  notes in detail for II year Botany.pptMARSILEA  notes in detail for II year Botany.ppt
MARSILEA notes in detail for II year Botany.ppt
 
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...
Legacy Analysis of Dark Matter Annihilation from the Milky Way Dwarf Spheroid...
 
World Water Day 22 March 2024 - kiyorndlab
World Water Day 22 March 2024 - kiyorndlabWorld Water Day 22 March 2024 - kiyorndlab
World Water Day 22 March 2024 - kiyorndlab
 
geometric quantization on coadjoint orbits
geometric quantization on coadjoint orbitsgeometric quantization on coadjoint orbits
geometric quantization on coadjoint orbits
 
Principles & Formulation of Hair Care Products
Principles & Formulation of Hair Care  ProductsPrinciples & Formulation of Hair Care  Products
Principles & Formulation of Hair Care Products
 
Controlling Parameters of Carbonate platform Environment
Controlling Parameters of Carbonate platform EnvironmentControlling Parameters of Carbonate platform Environment
Controlling Parameters of Carbonate platform Environment
 
Applied Biochemistry feedback_M Ahwad 2023.docx
Applied Biochemistry feedback_M Ahwad 2023.docxApplied Biochemistry feedback_M Ahwad 2023.docx
Applied Biochemistry feedback_M Ahwad 2023.docx
 
Alternative system of medicine herbal drug technology syllabus
Alternative system of medicine herbal drug technology syllabusAlternative system of medicine herbal drug technology syllabus
Alternative system of medicine herbal drug technology syllabus
 
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...
001 Case Study - Submission Point_c1051231_attempt_2023-11-23-14-08-42_ABS CW...
 
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptx
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptxSCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptx
SCIENCE 6 QUARTER 3 REVIEWER(FRICTION, GRAVITY, ENERGY AND SPEED).pptx
 
PSP3 employability assessment form .docx
PSP3 employability assessment form .docxPSP3 employability assessment form .docx
PSP3 employability assessment form .docx
 
Role of Herbs in Cosmetics in Cosmetic Science.
Role of Herbs in Cosmetics in Cosmetic Science.Role of Herbs in Cosmetics in Cosmetic Science.
Role of Herbs in Cosmetics in Cosmetic Science.
 
Main Exam Applied biochemistry final year
Main Exam Applied biochemistry final yearMain Exam Applied biochemistry final year
Main Exam Applied biochemistry final year
 
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdf
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdfSUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdf
SUKDANAN DIAGNOSTIC TEST IN PHYSICAL SCIENCE ANSWER KEYY.pdf
 
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...
Digitized Continuous Magnetic Recordings for the August/September 1859 Storms...
 
Gene transfer in plants agrobacterium.pdf
Gene transfer in plants agrobacterium.pdfGene transfer in plants agrobacterium.pdf
Gene transfer in plants agrobacterium.pdf
 
Physics Serway Jewett 6th edition for Scientists and Engineers
Physics Serway Jewett 6th edition for Scientists and EngineersPhysics Serway Jewett 6th edition for Scientists and Engineers
Physics Serway Jewett 6th edition for Scientists and Engineers
 

Context-oriented programming

  • 1. Lecture 08 :
 Context-Oriented Programming
 Overview and Applications LSINF 2335 Programming Paradigms Prof. Kim Mens Dr. Sebastián González UCL / EPL / INGI Disclaimer: any pictures used in this presentation remain with the copyright of their original owner and were included here for didactical purposes only. In case of any suspected violation of copyright please contact me so that I can remove or replace those pictures.
  • 2. Why? … through a programming language engineering approach enable context-driven behaviour adaptability …
  • 3. Hardware Phenomena 3 fixed (1980) mainframes servers desktops
 consoles portable (1990) laptops
 netbooks subnotebooks mobile (2000) handhelds
 tablets
 smartphones ‣ CPU load ‣ available memory (RAM) ‣ available storage (HD) ‣ date and time ‣ connected peripherals ‣ network peers ‣ touch screen ‣ geographical location ‣ GPS signal quality ‣ accelerometer ‣ wi-fi signal quality ‣ battery power ‣ camera ‣ microphone ‣ light sensor + + …
  • 4. text (1970) BSD SunOS MS DOS GNU/Linux graphical (1980) Mac OS Amiga OS Windows
 KDE, GNOME web (1990) static dynamic web 2.0 mashups mobile (2000) Symbian OS Windows CE iOS Android Software Phenomena 4 ‣ available libraries ‣ available hardware services ‣ available network services ‣ user task ‣ user expertise ‣ user preferences ‣ user privileges ‣ task urgency ‣ operation modes ‣ logging ‣ debugging ‣ degraded ‣ free trial ‣ partial failure ‣ domain specific ‣ [3D] wireframe / solid view ‣ [Maps] satellite / schematic ‣ ...
  • 5. Applications should be aware of their execution context, and should adapt dynamically to such context so that they can provide a service that matches client needs to the best extent possible. environmental properties humidity, light, noise, lighting network peers & services projector, GPS, storage internal state load, time, battery spatial state position, orientation, movement location semantics nearby objects & facilities users expertise, preferences Context Is Key 5
  • 6. take advantage of room projector for presentation peer service decrease playback quality when battery power is low internal state user task show parking spots and gas stations (only) when driving environmental conditions give more detailed indications when visibility is low disable phone ringtone in quiet places location semantics Adaptation Examples 6
  • 7. Why Aren’t We There Yet? 7 Richard Gabriel, 2006 Software systems today are produced according to a manufacturing model: a finished product is constructed at the factory and shipped to its final destination where it is expected to act like any other machine —reliable but oblivious to its surroundings and its own welfare.
  • 8. we still program this... using the programming models conceived for this.... (2010) (1980) Mindset Mismatch 8
  • 9. Current programming techniques and design principles invite programmers to think in a way that is mostly oblivious of the physical, technical and human environment in which the software will be used. Many chances of delivering improved services are thus missed. programming in isolation ? ? ? ? ? ? Current Mindset 9
  • 10. programming with context A new paradigm is needed that helps overcoming this limiting vision by putting programmers in the right state of mind to build dynamically adaptable applications from the ground up. Needed Mindset 10
  • 11. programming in isolation programming with context forward! ? ? ? ? ? ? Towards A Mindset Shift 11
  • 12. Conditional statementsDesign patternsPlugin architectures programming in isolation programming with context forward! ? ? ? ? ? ? Towards A Mindset Shift 11
  • 13. Adaptation Example 12 context behaviour ringtonedefault call reception behaviour
  • 14. Adaptation Example 12 context behaviour vibrationquiet call reception behaviour
  • 15. Adaptation Example 12 off-hook call waiting signal context behaviour call reception behaviour
  • 16. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 17. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 18. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 19. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 20. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 21. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 22. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 23. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 24. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 25. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 26. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 27. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 28. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 29. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 30. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 31. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 32. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 33. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 34. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 35. Adaptation Example 12 unavailable forward call context behaviour call reception behaviour
  • 36. Paradigmatic Shortcomings 13 class phone { method receive ( call ) { if ( phone.isOffHook( ) ) play( phone.callWaitingSignal( ), 2 );
 else if ( phone.environment( ).acoustics( ).isQuiet( ) ) phone.vibrate( 5 );
 else if ( phone.user( ).isUnavailable( ) ) forwardCall( call, phone.forwardNumber( ) ); else play( phone.ringTone( ), 10 ); } conditional statements
  • 37. class phone { method receive ( call ) { if ( ) then else if ( ) then else if ( ) then else } Paradigmatic Shortcomings 14 conditional statements
  • 38. class phone { method receive ( call ) { if ( ) then else if ( ) then else if ( ) then else } Paradigmatic Shortcomings 14 conditional statements Adaptable
  • 39. default phone user phone environment phone status class phone { method receive ( call ) { if ( ) then else if ( ) then else if ( ) then else } Paradigmatic Shortcomings 14 conditional statements Adaptable
  • 40. default phone user phone environment phone status class phone { method receive ( call ) { if ( ) then else if ( ) then else if ( ) then else } Paradigmatic Shortcomings 14 conditional statements Adaptable Tangled Scattered Fixed No reuse Complex logic
  • 41. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } special software architectures
  • 42. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures
  • 43. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures
  • 44. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures
  • 45. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures Modular Open
  • 46. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures Modular Open Infrastructural burden Anticipated adaptation points
  • 47. Paradigmatic Shortcomings 15 class Phone
 { attribute strategy; method receive ( call ) { strategy.receive( call ); } } class UnavailableStrategy
 { method receive ( call ) { ... } } class OffHookStrategy
 { method receive ( call ) { ... } } class QuietStrategy
 { method receive ( call ) { ... } } class DefaultStrategy
 { method receive ( call ) { ... } } Phone QuietStrategy OffHookStrategy UnavailableStrateg DefaultStrategy strategy.receive( call ); special software architectures Modular Open Infrastructural burden Anticipated adaptation points
  • 48. Paradigmatic Shortcomings 16 Software rigidness
 The variability points of the application are hard- coded in its architecture. It is difficult to add new variants non-invasively. Lack of modularity
 Tight coupling between core business logic and infrastructural code to manage the variants makes the software difficult to maintain and evolve. Mindset mismatch
 Programming tools make programmers oblivious of the context in which their applications will run. Programmers are not put in the right state of mind to build adaptable software. General Symptoms (Recap)
  • 49. Hypothesis 17 current programming tools adaptive systems we need to reengineer our tools A major obstacle for adaptability is the unavailability of appropriate context-aware programming languages and related tool sets.
  • 50. Approach 18 programming abstractions matter tool 1: C# using System; public class Program { static long Factorial(long number) { if(number <= 1) return 1; else return number * Factorial(number - 1); } static int Main(string[] args) { Console.WriteLine(Factorial(5)); return 0; } } tool 2: Ruby def fact(n) n <= 1 ? 1 : n * fact(n - 1) end fact(5) n! = { 1 n(n-1)! if n = 0 if n > 0 maintainability domain: math
  • 51. Approach A high-level language frees a program from much of its accidental complexity; it eliminates a whole level of complexity that was never inherent in the program at all. programming language engineering 19 Develop programming tools that reduce accidental complexity in the expression of context-driven behaviour adaptation Frederick Brooks, 1987 essential complexity ≠ accidental complexity
  • 52. Subjective-C What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Ambience 2008 20132011 Context Traits
  • 53. Subjective-C What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Ambience 2008 20132011 Context Traits
  • 54. Subjective-C What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Bringing Context to Mobile Platform Programming
  • 55. Context-Driven System Architecture 21 external context effect context information ActuatorsSensors arbitrated
 context changes World Context Discovery Context Management Active Context internal Application Behaviour
  • 56. Contexts As Situation Reifiers 22 computationally accessible data Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03
  • 57. Contexts As Situation Reifiers 22 computationally accessible data no semantics Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03
  • 58. Contexts As Situation Reifiers 22 computationally accessible data no semantics Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03 action can be taken well-defined situations Context Discovery Low battery charge High CPU load Firefox Landscape orientation
  • 59. Contexts As Situation Reifiers 22 computationally accessible data no semantics Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03 action can be taken well-defined situations Context Discovery contexts are reified situations for which adapted application behaviour can be defined Low battery charge High CPU load Firefox Landscape orientation
  • 60. Contexts As Situation Reifiers 22 computationally accessible data no semantics Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03 action can be taken well-defined situations Context Discovery contexts are reified situations for which adapted application behaviour can be defined Low battery charge High CPU load Firefox Landscape orientation LowBattery = new Context(); window.addEventListener(‘batterystatus’, function (battery) { if (battery.level < 30) LowBattery.activate(); else LowBattery.deactivate(); }); … in JavaScript
  • 61. Contexts As Situation Reifiers 22 computationally accessible data no semantics Battery charge = 220 mAh Idle cycles = 100 MHz User agent = “Mozilla/5.0...” Z axis = 0.03 action can be taken well-defined situations Context Discovery contexts are reified situations for which adapted application behaviour can be defined Low battery charge High CPU load Firefox Landscape orientation LowBattery = new Context(); window.addEventListener(‘batterystatus’, function (battery) { if (battery.level < 30) LowBattery.activate(); else LowBattery.deactivate(); }); … in JavaScript
  • 63. Standard Widget Spec UILabel class drawTextInRect: Draws the receiver’s text in the specified rectangle. - (void)drawTextInRect:(CGRect)rect Parameters rect The rectangle in which to draw the text. Discussion You should not call this method directly. This method should only be overridden by subclasses that want to modify the default drawing behavior for the label’s text. Availability Available in iOS 2.0 and later. Declared In UILabel.h 24
  • 64. Main Idea 25 @implementation UILabel (color) @contexts Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; return @resend(); } @end Application Behaviour
  • 65. Main Idea 25 @implementation UILabel (color) @contexts Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; return @resend(); } @end Application Behaviour Label
  • 66. Main Idea 25 @implementation UILabel (color) @contexts Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; return @resend(); } @end Application Behaviour
  • 67. Main Idea 25 @implementation UILabel (color) @contexts Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; return @resend(); } @end Open classes Objective-C COP Subjective-C Application Behaviour
  • 68. Main Idea 25 @implementation UILabel (color) @contexts Landscape - (void)drawTextInRect:(CGRect)rect { self.textColor = [UIColor greenColor]; return @resend(); } @end Open classes Objective-C COP Subjective-C ✓ Adaptation of any existing component ✓ No access to original source code needed ✓ Adaptations can be cleanly modularised Application Behaviour
  • 69. Context Relations Implication Antwerp Belgium Antwerp => Belgium Suggestion ClassRoom Quiet ClassRoom -> Quiet Requirement HDVideo BatteryHigh HDVideo =< BatteryHigh Exclusion Landscape Portrait Landscape >< Portrait 26 Context Management Combination Driving + UKDriving+UK Driving UK
  • 70. Avoiding Boilerplate 27 // Create contexts Context* Room = [[Context alloc] initWithName:@"Room"]; Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"]; Context* Day = [[Context alloc] initWithName:@"Day"]; Context* Night = [[Context alloc] initWithName:@"Night"]; … // Register contexts [CONTEXT addContext:Room]; [CONTEXT addContext:Bedroom]; [CONTEXT addContext:Day]; [CONTEXT addContext:Night]; … // Establish context relations [Day addExclusionRelationWith:Night]; [Bedroom addHardInclusionRelationWith:Room]; … // Register context-specific methods [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0]; …
  • 71. Avoiding Boilerplate 27 // Create contexts Context* Room = [[Context alloc] initWithName:@"Room"]; Context* Bedroom = [[Context alloc] initWithName:@"Bedroom"]; Context* Day = [[Context alloc] initWithName:@"Day"]; Context* Night = [[Context alloc] initWithName:@"Night"]; … // Register contexts [CONTEXT addContext:Room]; [CONTEXT addContext:Bedroom]; [CONTEXT addContext:Day]; [CONTEXT addContext:Night]; … // Establish context relations [Day addExclusionRelationWith:Night]; [Bedroom addHardInclusionRelationWith:Room]; … // Register context-specific methods [MANAGER addMethod:@selector(Context_Bedroom_getActiveRoom) forClass:[DomoticsServerViewController class] forContextNames:[[NSSet alloc] initWithObjects:@"Bedroom" ,nil] withDefautSel:@selector(getActiveRoom) withPriority:0]; … Relations: Day >< Night Sun >< Rain Livingroom -> TV Livingroom -> Window Livingroom -> Luminosity Livingroom -> Temperature Kitchen -> Luminosity Bedroom -> Temperature Bedroom -> Luminosity Bedroom -> Window Bathroom -> Temperature Bathroom -> Luminosity Bathroom => Room Kitchen => Room Livingroom => Room Bedroom => Room TV =< Electricity Luminosity =< Electricity Window =< Sun Contexts: Room Livingroom Kitchen Bedroom Bathroom Day Night TV Window Temperature Luminosity Sun Rain Electricity
  • 72. @implementation LowpassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = filterConstant; if(adaptive) alpha = ... // big formula to calculate the alpha level x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } -(NSString*)name { return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter"; } ... Case Study: Hard-Coded Operation Mode 28
  • 73. @implementation LowpassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = filterConstant; if(adaptive) alpha = ... // big formula to calculate the alpha level x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } -(NSString*)name { return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter"; } ... Case Study: Hard-Coded Operation Mode 28
  • 74. @implementation LowpassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = filterConstant; if(adaptive) alpha = ... // big formula to calculate the alpha level x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } -(NSString*)name { return adaptive ? @"Adaptive Lowpass Filter" : @"Lowpass Filter"; } ... Case Study: Hard-Coded Operation Mode 28 Operation mode (intrinsic context)Adaptive
  • 75. Case Study: Refactoring Using Logical Contexts 29 @implementation LowpassFilter @contexts LowPassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = [self getAlpha:accel]; x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } @contexts !Adaptive -(double) getAlpha:(UIAcceleration*)accel{ return filterConstant; } @contexts Adaptive LowPassFilter -(double) getAlpha:(UIAcceleration*)accel { return // big formula to calculate the alpha level; } Adaptive Adaptive
  • 76. Case Study: Refactoring Using Logical Contexts 29 @implementation LowpassFilter @contexts LowPassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = [self getAlpha:accel]; x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } @contexts !Adaptive -(double) getAlpha:(UIAcceleration*)accel{ return filterConstant; } @contexts Adaptive LowPassFilter -(double) getAlpha:(UIAcceleration*)accel { return // big formula to calculate the alpha level; }
  • 77. Case Study: Refactoring Using Logical Contexts 29 @implementation LowpassFilter @contexts LowPassFilter -(void)addAcceleration:(UIAcceleration*)accel { double alpha = [self getAlpha:accel]; x = accel.x * alpha + x * (1.0 - alpha); y = accel.y * alpha + y * (1.0 - alpha); z = accel.z * alpha + z * (1.0 - alpha); } @contexts !Adaptive -(double) getAlpha:(UIAcceleration*)accel{ return filterConstant; } @contexts Adaptive LowPassFilter -(double) getAlpha:(UIAcceleration*)accel { return // big formula to calculate the alpha level; } Relations: LowPassFilter >< HighPassFilter LowPassFilter => Filter HighPassFilter => Filter Contexts: Adaptive Paused LowPassFilter HighPassFilter Filter
  • 78. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo
  • 79. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-agnostic
  • 80. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-specific domain-agnostic
  • 81. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-specific domain-agnostic extrinsic
  • 82. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-specific intrinsic domain-agnostic extrinsic
  • 83. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-specific intrinsic domain-agnostic extrinsic physical
  • 84. Logging Context Scoping 30 Local contexts Global contexts Landscape LowBattery BusyCPU Antwerp • Affect all threads
 @activate(LowBattery) • Usually domain-agnostic
 – extrinsic to the application
 – based on physical phenomena • Activation follows external events • Local to one thread
 @activate(Adaptive in Thread1) • Usually domain-specific
 – intrinsic to the application
 – based on logical events • Activation follows business logic Adaptive Off-Hook HDVideo domain-specific intrinsic logical domain-agnostic extrinsic physical
  • 85. Summary 31 ✓ Clean application logic ✓ Clean modularisation of adaptations ✓ Context reification and management ✓ Run-time behaviour adaptation of any component (incl. 3rd party) ✓ No need for recompilation or access to original source code ✓ Maximises adaptation points while avoiding architectural burden ✓ Scoped adaptations language abstractions for adaptation to context … with sound technical underpinnings @context Landscape -id behaviour { // context-specific logic } Objects Open Classes Reflection Subjective Programming Context-Oriented Programming Subjective-C
  • 86. Subjective-C What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Ambience 2008 20132011 Context Traits
  • 87. Subjective-C What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Ambience 2008 20132011 Context Traits
  • 88. What? context-driven
 software adaptability through dedicated language abstractions and composition mechanisms Dynamic Behaviour Adaptation Through Run-Time Trait Recomposition Context Traits
  • 89. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren
  • 90. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren provided methods
  • 91. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren required methods
  • 92. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren sum operator
  • 93. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren =
  • 94. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren =
  • 95. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript =
  • 96. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = traits.js [ Van Cutsem & Miller 2011 ]
  • 97. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript =
  • 98. Traits As Basic Behavioural Units 33 T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript =
  • 99. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 100. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 101. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 102. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 103. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 104. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 105. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 106. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 107. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 108. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 109. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 110. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 111. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 112. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 113. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 114. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 115. Traits As Basic Behavioural Units 33 + + tag a1=”v1” a2=”v2” T.Element elementsByTagName elementsByAttribute getAttribute setAttribute walkChildren T.Element = Trait({ elementsByTagName: function(name) { ... }, elementsByAttribute: function(attr) { ... }, getAttribute: Trait.required, setAttribute: Trait.required, walkChildren: Trait.required }); ... in JavaScript = T.Tag tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute T.Node content parent appendChild replaceChild removeChild walkChildren XML.Element tagName addAttribute getAttribute setAttribute removeAttribute forEachAttribute content parent appendChild replaceChild removeChild walkChildren id elementsByTagName elementsByAttribute
  • 116. Default Behaviour & Context 34 HTML.Element addAttribute getAttribute ... style title T.HTML.Element class style title getAttribute setAttribute = XML.Element +
  • 117. Default Behaviour & Context 34 = HTML.Element + HTML.Anchor addAttribute ... href type target T.HTML.Anchor href type target getAttribute setAttribute HTML.Element addAttribute getAttribute ... style title T.HTML.Element class style title getAttribute setAttribute = XML.Element +
  • 118. Default Behaviour & Context 34 = HTML.Element + HTML.Anchor addAttribute ... href type target T.HTML.Anchor href type target getAttribute setAttribute HTML.Element addAttribute getAttribute ... style title T.HTML.Element class style title getAttribute setAttribute = XML.Element + HTML.Element = Trait.compose(XML.Element, T.HTML.Element); HTML.Anchor = Trait.compose(HTML.Element, T.HTML.Anchor); ... in JavaScript
  • 119. Default Behaviour & Context 34 = HTML.Element + HTML.Anchor addAttribute ... href type target T.HTML.Anchor href type target getAttribute setAttribute Default ... for prototypical situations Prototypical behaviour ... HTML.Element addAttribute getAttribute ... style title T.HTML.Element class style title getAttribute setAttribute = XML.Element + ( unperturbed system ) HTML.Element = Trait.compose(XML.Element, T.HTML.Element); HTML.Anchor = Trait.compose(HTML.Element, T.HTML.Anchor); ... in JavaScript
  • 120. Default Behaviour & Context 34 = HTML.Element + HTML.Anchor addAttribute ... href type target T.HTML.Anchor href type target getAttribute setAttribute Default ... for prototypical situations Prototypical behaviour ... HTML.Element addAttribute getAttribute ... style title T.HTML.Element class style title getAttribute setAttribute = XML.Element + ( unperturbed system ) HTML.Element = Trait.compose(XML.Element, T.HTML.Element); HTML.Anchor = Trait.compose(HTML.Element, T.HTML.Anchor); ... in JavaScript
  • 121. Context + Traits 35 ... in JavaScriptContext Traits let Default ∈ C Default = new Context();
  • 122. Context + Traits 35 ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L
  • 123. Context + Traits 35 ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T
  • 124. Context + Traits 35 W3Clet W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T
  • 125. Context + Traits 35 W3Clet W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T
  • 126. Context + Traits 35 W3Clet W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T
  • 127. Context + Traits 35 W3Clet W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 128. Context + Traits 35 W3Clet W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits Untrusted let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); let Untrusted ∈ C Untrusted = new Context(); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 129. Context + Traits 35 W3C constitution ( ida, Untrusted ) = Untrusted.adapt
 (a, T.SecureAnchor); let W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits T.SecureAnchor href parent visible manager ... Untrusted let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); let Untrusted ∈ C Untrusted = new Context(); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 130. Context + Traits 35 W3C constitution ( ida, Untrusted ) = Untrusted.adapt
 (a, T.SecureAnchor); let W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits T.SecureAnchor href parent visible manager ... Untrusted let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); let Untrusted ∈ C Untrusted = new Context(); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 131. Context + Traits 35 W3C constitution ( ida, Untrusted ) = Untrusted.adapt
 (a, T.SecureAnchor); let W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits T.SecureAnchor href parent visible manager ... Untrusted let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); let Untrusted ∈ C Untrusted = new Context(); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 132. Context + Traits 35 W3C constitution ( ida, Untrusted ) = Untrusted.adapt
 (a, T.SecureAnchor); let W3C ∈ C W3C = new Context(); ... in JavaScriptContext Traits T.SecureAnchor href parent visible manager ... Untrusted let Default ∈ C Default = new Context(); a = new HTML.Anchor();let ida ∈ L constitution: L ⨉ C → T constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor); let Untrusted ∈ C Untrusted = new Context(); T.ValidAnchor addAttribute setAttribute removeAttribute parent ...
  • 133. Run-Time Trait Recomposition 36 overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
  • 134. Run-Time Trait Recomposition 36 overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
  • 135. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target HTML.Anchor addAttribute setAttribute removeAttribute href parent visible type target T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.SecureAnchor href parent visible manager ... overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = ▹ ▹ overriding operator
  • 136. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target HTML.Anchor addAttribute setAttribute removeAttribute href parent visible type target T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.SecureAnchor href parent visible manager ... overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = ▹ ▹ addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 137. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 138. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 139. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 140. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 141. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 142. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 143. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 144. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 145. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 146. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 147. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 148. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 149. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 150. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 151. Run-Time Trait Recomposition 36 o addAttribute setAttribute removeAttribute href parent visible type target overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C → 2T defined through composition policiescomposition: 2T → O constitution ( ida, { Default, Untrusted, W3C } ) = { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } composition ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = o = TC1 · TC2 · ... · TCn puts object composition in direct relationship to the context of execution object: L ⨉ 2C → O object = composition · constitution addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent
  • 162. Composition Policies 38 addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible?
  • 163. Composition Policies 38 addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers)
  • 164. Composition Policies 38 addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { }
  • 165. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { }
  • 166. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) exclusion operator Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { }
  • 167. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { } P : 2T → 2T P = Povr · Pbysec
  • 168. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = ✓Arbitrary combinations HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { } P : 2T → 2T P = Povr · Pbysec
  • 169. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = ✓Arbitrary combinations HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { } P : 2T → 2T P = Povr · Pbysec
  • 170. Composition Policies 38 Pbysec ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { HTML.Anchor, T.SecureAnchor – visible, T.ValidAnchor } addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parent visible addAttribute setAttribute removeAttribute parent = ✓Arbitrary combinations HTML.Anchor T.SecureAnchor T.ValidAnchor▹ ▹ o addAttribute setAttribute removeAttribute href parent visible type target addAttribute setAttribute removeAttribute href parent visible type target href parentparent addAttribute setAttribute removeAttribute What if we want to bypass security of visible? ✗ Impossible with strict overriding semantics (e.g. inheritance, mixins, COP layers) Povr ( { HTML.Anchor, T.SecureAnchor, T.ValidAnchor } ) = { } P : 2T → 2T P = Povr · Pbysec
  • 171. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... HTML.Anchor ... setAttribute ...
  • 172. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... HTML.Anchor ... setAttribute ...
  • 173. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? HTML.Anchor ... setAttribute ...
  • 174. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ...
  • 175. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... aliasing operator
  • 176. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ...
  • 177. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition →
  • 178. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ...becomes requirement
  • 179. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... how to invoke overridden behaviour? T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition →
  • 180. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹
  • 181. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹
  • 182. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 183. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 184. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 185. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 186. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 187. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 188. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 189. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 190. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 191. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 192. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 193. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 194. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 195. Behaviour Extensibility Challenge 39 T.ValidAnchor addAttribute setAttribute removeAttribute parent ... T.ValidAnchor.setAttribute = function(name, value) { ... return self.htmlSetAttribute(name, value); } T.ValidAnchor’ addAttribute setAttribute removeAttribute parent htmlSetAttribute ... HTML.Anchor ... setAttribute ... [ htmlSetAttribute ↦ setAttribute ] = HTML.Anchor’ ... setAttribute htmlSetAttribute ... → manual edition → ▹ ✗ bypassed T.SecureAnchor ▹▹ ✗ hard-coded choice of overridden behaviour
  • 196. Extensibility Through Proceed 40 HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour?
  • 197. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour? proceed
  • 198. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent becomes requirement how to invoke overridden behaviour? proceed
  • 199. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour? proceed
  • 200. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent ✓ open choice of overridden behaviour how to invoke overridden behaviour? proceed
  • 201. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour? proceed ▹ T.SecureAnchor ... setAttribute ... parent visible manager ... ▹
  • 202. Extensibility Through Proceed 40 T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour? proceed ▹ T.SecureAnchor ... setAttribute ... parent visible manager ... ▹
  • 203. Extensibility Through Proceed 40 T.Extensible proceed Dynamic T.ValidAnchor = Trait({ setAttribute: function(name, value) { ... // validity check return self.proceed(); }, ... }); HTML.Anchor ... setAttribute ... T.ValidAnchor addAttribute setAttribute removeAttribute parent how to invoke overridden behaviour? proceed ▹ T.SecureAnchor ... setAttribute ... parent visible manager ... ▹
  • 204. Summary 41 ✓ Contexts: frame of reference to define adaptations ✓ Traits: convenient units of adaptation ✓ Policies: flexible compositions (e.g. non-linear) ✓ Extensibility: independent behaviour extensions ✓ JavaScript: easy definition of contexts, traits, and composition direct causal connection composition of the computational system situation in which the system executes ⇋ Context Traits
  • 205. How? Subjective-CAmbience 2008 20132011 Context Traits implementation of context-driven
 software adaptability through … … method dispatch … and method pre-dispatch.
  • 206. Method Pre-Dispatch 43 When a context is (de)activated, for every class and selector the context adapts, find all active methods M(c, s)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and deploy the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation
  • 207. Method Pre-Dispatch 43 When a context is (de)activated, for every class and selector the context adapts, find all active methods M(c, s)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and deploy the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation deploy
  • 208. Method Pre-Dispatch 43 When a context is (de)activated, for every class and selector the context adapts, find all active methods M(c, s)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and deploy the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation structural reflection deploy
  • 209. Method Dispatch 44 When a message is received, find all applicable methods for the given message (with receiver r, selector s and arguments a) M(r,s,a)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and invoke the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation
  • 210. Method Dispatch 44 When a message is received, find all applicable methods for the given message (with receiver r, selector s and arguments a) M(r,s,a)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and invoke the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation message is received
  • 211. Method Dispatch 44 When a message is received, find all applicable methods for the given message (with receiver r, selector s and arguments a) M(r,s,a)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and invoke the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation invoke message is received
  • 212. Method Dispatch 44 When a message is received, find all applicable methods for the given message (with receiver r, selector s and arguments a) M(r,s,a)={ m1, m2, m3, ..., mn } reorder them according to specificity m1 < m2 < m3 < ... < mn and invoke the first one m1 ‣m1 is the most specific implementation for the current context ‣ resend invokes the remaining methods in order ‣mn is (usually) the default implementation [ behavioural reflection ] invoke message is received
  • 213. Method Pre-Dispatch 45 Is the method order always defined? • Could there be no applicable methods? ➡ default implementation • Could there be non-comparable methods? ➡ the order should be total ➡ if not, we’re in trouble M(r,s,a)={ m1, m2, m3, ..., mn } M(c, s)={ m1, m2, m3, ..., mn }
  • 215. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 Default impl Landscape impl Portrait impl (1.0)
  • 216. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 Default impl Landscape impl Portrait impl vtable (1.0)
  • 217. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 Default impl Landscape impl Portrait impl (1.0)
  • 218. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 Default impl Landscape impl Portrait impl (1.0)
  • 219. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 @activate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 220. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 @activate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 221. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 222. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 223. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 ‣ no additional cost for method invocations ‣ cost incurred at context switching time @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 224. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 ‣ no additional cost for method invocations ‣ cost incurred at context switching time @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 225. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 ‣ no additional cost for method invocations ‣ cost incurred at context switching time @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)
  • 226. Subjective-C Dynamic Method Pre-Dispatch 47 UILabel
 @property NSString *text
 @property UIFont *font
 ...
 - (void)Portrait_drawTextInRect:(CGRect)rect
 - (void)Landscape_drawTextInRect:(CGRect)rect
 - (void)Default_drawTextInRect:(CGRect)rect
 - (void)drawTextInRect:(CGRect)rect
 ‣ no additional cost for method invocations ‣ cost incurred at context switching time @activate(Landscape); @deactivate(Landscape); Default impl Landscape impl Portrait impl (1.0)