05.08.2014 Views

here - Stefan-Marr.de

here - Stefan-Marr.de

here - Stefan-Marr.de

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.2. Case Studies<br />

Immutability In an attempt to go beyond the guarantees provi<strong>de</strong>d by Clojure’s<br />

agent implementation, Sec. 5.3.2 discussed how immutability can be<br />

guaranteed.<br />

Ad Hoc Solution Enforcing immutability on top of a VM that neither supports<br />

it directly nor provi<strong>de</strong>s mechanisms for managing mutation is a challenge.<br />

While Java’s SecurityManager can provi<strong>de</strong> a partial solution, it cannot<br />

be used to enforce immutability for public object fields (cf. Sec. 3.3.5). Thus,<br />

an ad hoc solution would require implementing managed mutation including<br />

support for handling primitives. This could potentially be done using AOP<br />

for instance with AspectJ, 3 or program transformation as it is used for the implementation<br />

of the OMOP (cf. Sec. 7.1). Thus, it takes additional mechanisms<br />

to realize immutability on top of a JVM or Smalltalk for instance.<br />

OMOP-based Solution With the OMOP’s support for managed state,<br />

the foundation is already available, and an ImmutableDomain such as given<br />

in Lst. 6.3 can be <strong>de</strong>fined. The ImmutableDomain adapts field access operations<br />

by customizing #write:toField:of:. This prevents any mutation from<br />

succeeding for any object, i. e., any object that is owned by the immutable<br />

domain. Note that on line 24 of Lst. 6.1, the ImmutableDomain adopts the return<br />

value of an update function. Furthermore, note that it handles the issue<br />

of reflection by customizing not only the writing of fields but also all<br />

primitive operations, which inclu<strong>de</strong>s the primitives used for reflection, e. g.,<br />

#priminstVarAt:put:on:.<br />

Handled Challenges With this case study, the evaluation showed solutions<br />

for two of the common implementation challenges (cf. Tab. 6.1). It uses the<br />

OMOP’s mechanisms to intercept all mutating operations, i. e., writing to object<br />

fields and primitives performing mutation. This is an example of a solution<br />

to provi<strong>de</strong> immutability also against reflective operations when <strong>de</strong>sired,<br />

and it shows how the problems of <strong>de</strong>fining state access policies can be solved.<br />

Furthermore, this case study <strong>de</strong>monstrates that the OMOP satisfies the requirements<br />

for managed state, because it reifies all state access and enables<br />

its customization.<br />

3 http://www.eclipse.org/aspectj/<br />

147

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!