c# - Create reusable processing logic on top of predefined blocks with TPL dataflow? -


i love tpl dataflow.

well, interesting design choice that, predefined block use delegates allow implement processing logic. looks in simple scenarios. let's think real world big applications, requires modularity , encapsulation. found hard , unnatural write structured app delegate approach.

for example, if want multiplyintbytwotransformblock , noopactionblock reusable class type (not instance). how achieve it? wish can inherit transformblock/actionblock , say, override process() method achieve this. predefined blocks sealed. accept delegates.

i know can create custom block scratch complex me because need little customization on top of predefined ones.

so, how achieve goal?

update: not saying there things delegates cannot do. saying exposing abstract blocks in template method pattern better in many scenarios. say, wish can write abstractmultiplyblock , multiplybytwoblock , multiplybythreeblock, taking advantage of polymorphism. delegates, unfortunately not provide such kind of data&logic reusability.

i don't see reason why need custom block types that. helper methods should enough:

public static ipropagatorblock<int, int> createmultiplyinttransformblock(     int multiplier) {     return new transformblock<int, int>(i => * multiplier); }  public static ipropagatorblock<int, int> createmultiplyintbytwotransformblock() {     return createmultiplyinttransformblock(2); } 

if think delegate isn't enough you, maybe you're trying put logic in wrong place. there no reason why delegate can't use objects use encapsulation , modularity properly. way, application logic stays separate logic of executing code.

but if wanted you're asking about, encapsulating transformblock in custom class implements ipropgatorblock , has abstract process() method. doing complicated, have @ guide implementing custom tpl dataflow blocks details.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -