Posts

Showing posts from August, 2013

OO design patterns from a functional programming perspective

Here my attempt to match up design patterns with functional programming constructions: Chain of responsibility Fold request across the chain of handlers, at each step returning either (using Either type) request to continue fold (possibly with transformed request), or returning handled request indicating that fold is finished. Command Request is held in data (e.g. as discriminant union) Interpreter Language is available as typed data structure (e.g. discriminant union) and is interpretable with functions calls. Alternative:Language is defined in monadic form (e.g. as function calls)  and is interpreted as part of the monad's interpretation. Iterator Exposed traversal functions hide data structure of containers. Functions typically work on zipper focus adapted to the containers structure.   Mediator Exposed functions stay at top/root of exposed data structures. Memento Use immutability and exposure of intermediate states to allow recovery, restart or alternate...