Skip to content

Generic Function Pattern

在 阅读 wiki.c2 External Polymorphism 时,其中提及了Generic Function Pattern。

wiki.c2 Generic Function

NOTE: 其实我们经常使用, 但是没有对它进行命名

A GenericFunction implements ExternalPolymorphism and MultipleDispatch by maintaining a dispatch table that associates parameter types with FunctorObjects. When a GenericFunction is called it uses the dynamic types of its parameters as keys into the dispatch table in order to retrieve a specialized FunctorObject. The call is then delegated to the FunctorObject.