An Adaptive Object Model with Dynamic Role Binding - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

An Adaptive Object Model with Dynamic Role Binding

Description:

Objects reside in an environment or in multiple environments at a time. ... http://www.graco.c.u-tokyo.ac.jp/ ~ichiyama/rolemodel. Implementation on Java ... – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 41
Provided by: poslMinni
Category:

less

Transcript and Presenter's Notes

Title: An Adaptive Object Model with Dynamic Role Binding


1
An Adaptive Object Model with Dynamic Role Binding
  • Tamai, T. (U. Tokyo),
  • Ubayashi, N. (Kyushu Inst. Tech.),
  • Ichiyama, R. (U. Tokyo)

2
Objects Environments
  • Objects reside in an environment or in multiple
    environments at a time.
  • Objects change their behavior according to
    environments
  • e.g. day/night, weekdays/weekend
  • Objects evolve to adapt to environment changes.

3
Example (1) Adaptation (Honda et al. 92)
  • Objects adapt to multiple environments.
  • Hanako (object) is a wife in her family and a
    researcher at office.She preserves her identity
    even if she retires from office.

4
Example (2) Multiple Roles (M. Fowler)
  • Personnel roles in a company
  • roles engineers, salesmen, directors, and
    accountants
  • cases
  • a person plays more than one roles
  • a person changes roles

5
Example (3) Role Patterns (E. Kendall)
  • bureaucracy dealing patterns
  • roles director, manager, subordinate, clerk,
    client
  • patterns
  • dealing client deals with clerk
  • bureaucracy manager subordinate are
    subclasses of clerk manager supervises
    subordinate and reports to director

6
A New Role Model Epsilon
  • Design goals
  • support adaptive evolution
  • enable separation of concerns
  • advance reuse

7
Features of Epsilon
  • Contexts encapsulate collaboration fields
    enclosing a set of roles.
  • Objects freely enter a context assuming roles and
    leave a context discarding roles.
  • Objects can belong to multiple contexts at a
    time.
  • Contexts (with roles) are independent reuse
    components to be deployed separately from
    objects.

8
Programming LanguageEpsilonJ
  • A language based on Epsilon model
  • Constructs for defining a context enclosing roles
    to describe and encapsulate collaboration
  • Dynamic binding and unbinding mechanism of an
    object and a role

9
Declaration of Context and Roles
  • context Company
  • static role Employer / static means
  • singleton
    instance /
  • int salary100
  • void pay()
  • Employee.getPaid(salary)
  • role Employee
  • int save
  • void getPaid(int salary)
  • savesalary

10
  • Context and roles are like class and inner
    classes but roles are more concrete and couplings
    among them are stronger.(Context is composition
    rather than aggregation.)
  • Roles can see only each other and methods/fields
    of its context.

11
Binding Objects with Role
  • class Person
  • string name
  • Person tanakanew Person()
  • Person sasakinew Person()
  • Company todainew Company()
  • todai.Employer.bind(sasaki)
  • todai.Employee.newBind(tanaka)

12
Objects Acquire New Functions through Binding
  • sasaki.(todai.Employer).pay()
  • tanaka.(todai.Employee).getPaid()
  • Objects can access to functions of contexts
    (collaboration fields) only through binding to
    roles.

13
Role may have Multiple Instances
  • Person suzukinew Person()
  • todai.Employee.newBind(suzuki)
  • Binding is between an object and a role instance.
  • newBind is a two step process (new
    todai.Employee()).bind(suzuki)
  • Role here shows a feature of class.
  • Both ways of handling those roles as a collection
    and by instance are provided.

14
Method Import/Export by Binding
  • Binding an object to a role affects states and
    behavior of the object and the role (interaction
    between the object and the role).
  • Interface for binding can be defined and used in
    binding.

15
Role Interface
  • interface PersonI void deposit(int)
  • context Company ...
  • role Employee requires PersonI
  • void getPaid(int salary)
  • deposit(salary)

16
Method Binding as Importing Interface
  • class Person
  • string name int money
  • void deposit(int s) moneys
  • Person tanaka new Person()
  • todai.Employee.newBind(tanaka)
  • / Hereafter, when deposit of todai.Employee role
    instance that tanaka is bound to is invoked,
    the object method deposit is called instead. /

17
Method Import with Renaming
  • class Person
  • string name int money
  • void save(int s) moneys
  • Person tanaka new Person()
  • todai.Employee.newBind(tanaka) replacing
    deposit(int) with save(int)

18
Method Overriding and Call of Super
  • interface PersonI void deposit(int)
  • context Company ...
  • role Employee requires PersonI
  • void deposit(int salary)
  • ...
  • super.deposit(salary)

19
Method Binding as Exporting Interface
  • class Person
  • string name int money
  • void save(int s) moneys
  • todai.Employee.newBind(tanaka) replacing
    deposit(int) with save(int)
  • / Hereafter, when save of tanaka is invoked,
    role method deposit is called instead. /

20
import
import export (overriding and call of
super)
Context
role
Context
role
export (overriding)
Context
role
21
Object Method Replacing Multiple Role Methods
  • An object method may replace multiple role
    methods.
  • Case 1 replaced methods are all imported (not
    overridden)
  • Case 2 replaced methods are all exported
    (overridden)
  • Case 3 some imported, others exported

22
Object Method Replacing Multiple Role Methods(2)
  • Case 1 simple
  • Case 2 when the object method is called, all the
    overriding methods are invoked in an undefined
    order.
  • Case 3 imported method is always the current
    overridden method, except super

23
Comparison to AspectJ Advice Precedence
  • No complex precedence rule.
  • Principle binding/unbinding is dynamic.
  • The current status of binding is always
    respected.

24
Example Integrated Systems
  • When a component takes an action, related
    components behave accordingly.
  • E.g. integrated environment of editor/compiler/deb
    ugger

25
A Simplified Model
  • A simple integrated system (Sullivan et al., 02)

Keep the pair of Bits in the same state
Bit //binary state set() clear()
One way relation
26
Scalability and Evolvability
  • Is it easy to add a new node?
  • Is it easy to add a new type of nodes?
  • Is it easy to add a new relation?
  • Is it easy to add a new type of relations?

27
Conventional approaches do not work nicely
  • Simple OO mixes Bit Relations description.
  • Design patterns, Mediator and Observer, do not
    fit either.
  • AspectJ solution also has problems.
  • New approaches have been proposed
  • ABT (Sullivan Notkin 92)
  • Association Aspect (Sakurai et al. 04)

28
Mediator Pattern
  • Bit class must know each Mediator (Equality,
    Trigger, etc.)? Bit depends on Mediator

Colleague
Mediator
Equality
Bit
Equality e1,e2
e1.notify() e2.notify()
void set() void clear()
29
Observer Pattern
  • Better for dealing with the case a Bit instance
    involved in multiple relations
  • Bit must inherit Subject and must use its method
    notify.

Subject
Observer
Bit
Equality
void set() void clear()
void update()
notify()
30
Using AspectJ
  • Doesnt work nicely (Sullivan et al.)
  • Implementing Equality as an Aspect does not scale
    for new equality introduction.
  • Preventing unbounded recursion doesnt work due
    to lack of Aspect instantiation. (Sakurai et al.)

31
Probable Solutions
  • A table to keep all relations
  • local problems solved globally
  • ABT (Sullivan Notkin 92)
  • Object(Bit) defines operations (set, clear) and
    also announces events (justset, justcleared).
  • Mediator listens to events and invoke
    corresponding operations.

32
Our Solution
  • class Bit
  • boolean statefalse
  • void set() statetrue
  • void clear() statefalse
  • boolean get() return state
  • interface ActorInterface
  • void fire()

33
context Equality boolean busyfalse role
Actor1 requires ActorInterface void fire()
super.fire() if(!busy)
busytrue Actor2.fire()
busyfalse role Actor2 //likewise ...

34
Equality
Actor1
Actor2
fire()
fire()
35
Bit b1new Bit() Bit b2new Bit() Bit b3new
Bit() Bit b4new Bit() Equality e12new
Equality() Equality e23new Equality() Trigger
t34new Trigger() e12.Actor1.bind(b1) replacing
fire() with set() e12.Actor2.bind(b2) replacing
fire() with set() e23.Actor1.bind(b2) replacing
fire() with set() ......
36
Results
  • Bit and Equality are totally independent and
    reusable.
  • It scales to new relation instance introduction
    and new type relation introduction.

37
Comparison with Caesar
  • Observer pattern example (Mezini Ostermann 03)
  • The goal of Caesar is to decouple aspect
    interface, aspect implementation and aspect
    binding.

38
Aspect Collaboration Interface in Caesar
  • interface ObserverProtocol
  • interface Subject
  • provided void addObserver(Observer o)
  • provided void removeObserver(Observer o)
  • provided void changed()
  • expected String getState()
  • interface Observer
  • expected void notify(Subject s)

39
ACI Implementation in Caesar
  • class ObserverProtocolImpl
  • implements ObserverProtocol
  • class Subject
  • List observers new LinkedList()
  • void addObserver(Observer o)
  • observers.add(o)
  • void removeObserver(Observer o)
  • observers.remove(o)
  • void changed()
  • Iterator it observers.iterator()
  • while (iter.hasNext())
  • ((Observer)iter.next()).notify(this)

40
EpsilonJ Solution
  • context ObserverPattern
  • static role Subject
  • requiresvoid changed()
  • void changed()
  • super.changed()
  • Observer.notify(this)
  • role Observer
  • requiresvoid notify(Subject)

41
Description in EpsilonJ
  • Much more concise
  • Crucial behavior of Observer Pattern is not
    expressed in Caesar ACI but clearly visible in
    EpsilonJ.
  • Binding mechanism in EpsilonJ is much simpler.

42
Other Examples
  • Mediator Pattern
  • Observer Pattern
  • Visitor Pattern
  • Kendalls example
  • Rental shop
  • Dining philosophers

43
Implementation
  • Bunraku Epsilon implementation in Ruby (by R.
    Ichiyama)
  • Features of context and role declaration, binding
    (with replacing), and unbinding are all
    implemented.
  • http//www.graco.c.u-tokyo.ac.jp/ichiyama/rolemo
    del

44
Implementation on Java
  • Use the annotation feature of Java2 5.0
  • Syntax is a little modified.
  • Full implementation is still ongoing.

45
Related Work
  • AOP AspectJ
  • describe aspects separately and weave them
    together. - Kiczales et al. 97.
  • MDSOC Hyper/J
  • separate multiple concerns to different
    dimensions and integrate them. - Ossher Tarr
    01
  • Composition Filters (Aksits et al.)
  • Demeter Adaptive Methods (Lieberherr et al.)

46
Related Work(2)
  • various role models
  • D. Riehle
  • B. Kristensen et al.
  • L. Wieringa et al.
  • contracts
  • Helm, Holland, Gangopadhyay 90
  • multiple inheritance
  • mixin - Bracha Cook 90, McJava(Kamina Tamai
    04)
  • delegation (Self etc.)

47
Future Work
  • Full implementation
  • Larger examples
Write a Comment
User Comments (0)
About PowerShow.com