ObjectFunctionalPatterns
Last edit April 5, 2010
ObjectFunctionalPatterns
describe ways to adapt features and strategies usually found in
FunctionalProgrammingLanguage
s for use in
ObjectOrientedProgramming
. Some of these are
ProtoPattern
s, but many are not.
ThomasKuehne
first brought these concepts to Wiki with his
FunctionalPatternSystemForObjectOrientedDesign
and many patterns in this language originate from his PhD thesis which is a book by the same name.
FunctorObject
shows how to treat functions as first class objects. This is useful for implementing
HigherOrderFunction
s in an
ObjectOriented
environment.
GenericFunction
and
GenericFunctionObject
describe how to implement
ExternalPolymorphism
and
MultipleDispatch
-- features normally found only in
FunctionalProgrammingLanguage
s. These mechanisms allow us to make verb based abstractions in addition to the noun based abstractions that
ObjectOriented
languages give us. When objects are used in these abstractions they become passive rather than active which gives us a wider range of expression.
FunctionCallObject
is a
ProtoPattern
that describes how to treat the stack frame of a function call as a first class object it is very closely related to
LazyObject
. If
FunctionCallObject
s can be made to work then
ContinuationsAndCoroutines
can be used in an OO environment and can potentially reduce or eliminate the need for threads.
Programs can be made more efficient by delaying computations using
LazyEvaluation
and caching the results (see
CallByNeed
).
LazyObject
s are one way of doing this.
LazyEvaluation
has its problems though. In an world where state is mutable
LazyEvaluation
can be
too
lazy. Immutable
ValueObject
s and
CommandQuerySeparation
can be used to protect against aliasing and side-effects.
InternalIteration
can make code easier to read and write.
FunctorObject
s enable their use, but they do have some limitations especially when it comes to flexibility. The
TransfoldPattern
shows how to
InternalizeExternalIterators
in order to simultaneously iterate over multiple collections.
The
TranslatorPattern
extends the concept of
ExternalPolymorphism
to objects and more importantly aggregates of objects. So that these aggregates can be used in new contexts without having to be re-opened and extended.
You can get a complete list of these patterns by going to
CategoryObjectFunctionalPatterns
and clicking on the title.
I wonder if
ThomasKuehne
s
ValueObjectPattern
has any details that are missed on the
ValueObject
page. Similarly I wonder if there is any difference between his
VoidValue
and our more familiar
NullObject
.
See
FunctionalPatternSystemForObjectOrientedDesign
,
ObjectFunctionalImplementation
.
See also
ObjectFunctional
CategoryPatternLanguage
CategoryFunctionalProgramming
CategoryMultiparadigm