| app |
+---------------+
^ |
| V
+-----+ +-----+
| | | |
+----------| |-| |-+
| protocol | .up | |.down| |
+----------| |-| |-+
| | | |
+-----+ +-----+
^ |
| V
+---------------+
| socket |
My solution was to make a Protocol class, which created an Up Transform
and a Down Transform
.
The Protocol constructor passes a reference (to itself) when constructing the Up and Down transforms. The _transform
method in each of the up and down transforms can then call push
on itself, on the other Transform
, or both as required. Common state can be kept in the Protocol
object.