8.11 Custom Types

It is generally frowned upon to pass a custom class through a Tuple stream. One one hand this increases coupling of custom Operations to a particular type, and it removes opportunities for reducing the amount of data that passes over the network (or is serialized/deserialized).

To overcome the first objection, with every custom type with multiple instance fields, attempt to provide Functions that can promote a value from the custom object to a position in a Tuple or demote the Tuple value to a particular field back into the custom type. This allows existing operations (like ExpressionFunction or RegexFilter) to operate on values owned by a custom type. For example, if you have a Person object, have a Function named GetPersonAge that takes Person as an argument and only returns the age as the result. The next operation can then Filter all Persons based on their age. This may seem like more work and less effiicient, but it keeps your application flexible and reduces the amount of duplicate code (the only alternative here is to create a PersonAgeFilter which results in one more thing to test).

Copyright © 2007-2008 Concurrent, Inc. All Rights Reserved.