lundi 29 septembre 2008

Java to W-Language. The Propagator Pattern

Today we'll pick up this programming perl written in Java and port it into the W-Language.

The Java code implements the Propagator pattern.

The Propagator pattern belongs to a family of patterns for consistently updating objects in a dependency network. The propagator patterns are found in such diverse applications as MAKE, WWW, spreadsheets, GUIs, reactive control systems, simulation systems, distributed file systems, distributed databases, workflow systems and multilevel caches.

Let's start with the Java code :

public abstract class StrictPropagator {
private Vector dependents;

// The constructor
StrictPropagator(int initialCapacity) {

dependents = new Vector(initialCapacity);

abstract synchronized void update(StrictPropagator from);

public synchronized void notifyDependents(){
Enumeration e = dependents.elements();
StrictPropagator d;
while (e.hasMoreElements()) {
d = (StrictPropagator)e.nextElement();

public synchronized void addDependent(StrictPropagator d) {

public synchronized void removeDependent(StrictPropagator d) {


Now let's have a look at the W-Language code :

StrictPropagator is class
dependents is array of 0 StrictPropagator

PROCEDURE Constructor( )
// We have no need to pre-allocate our array/ java vector

PROCEDURE VIRTUAL update(from is StrictPropagator)

PROCEDURE notifyDependents()
d is StrictPropagator dynamic
FOR EACH ELEMENT d OF :dependents
d:update( object )

PROCEDURE addDependents(D is StrictPropagator)
ArrayAdd( :dependents, D )

PROCEDURE removeDependents(d is StrictPropagator)
ind is int = ArraySeek(:dependents, asLinearFirst, d)
IF ind <> -1 THEN ArrayDelete(:dependents, ind)

Unfortunately the W-Language has no special keyword for
abstract classes.
Don't care too much about that. Just keep in mind that you should not instantiate from an abstract class.

- A Java Vector is in W-Language terminology a dynamic array

- The
synchronized statement can be replaced as shown :
CriticalSectionStart() / CriticalSectionEnd()

- The Java keyword this, has (in this case) the same meaning as the W-language object keyword.

That's it for the moment ... I hope my code coloring makes sense to you.

In the next blog I'll talk about how you can use this pattern in GUI applications, show the UML etc. Stay tuned!

The Propagator pattern is based on a work of :
Peter H. Feiler
Software Engineering Institute
Carnegie Mellon University

Walter F. Tichy
Institute for Informatics
University of Karlsruhe

Aucun commentaire: