Path: csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Sebastian Newsgroups: comp.lang.java.programmer Subject: Re: OO Design Patterns vs FP Date: Wed, 02 Oct 2013 21:31:14 +0200 Organization: albasani.net Lines: 66 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net MLgHJkEIF0t/vmGUzGZdYP1CnoBKdIUi3USe5n22fn6G1NpvrZq5CH65U5PoU5GAItSRxos73nzxMTKRkWXXIA== NNTP-Posting-Date: Wed, 2 Oct 2013 19:30:27 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="xzPisgjdHSaDXjfJyvZZ5qF0HRhd2XwJs69TFf8+phPNfzMzDDtXS+xW7r98MzY3lP3GN8WDryW+okDSYNxs1HO50wGMlRpr0ZZ8fEwmd80BwDIldhVlI7duCePXT9pc"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Cancel-Lock: sha1:cl6nbaBhGi923CrI0T36GH28N2U= Xref: csiph.com comp.lang.java.programmer:25435 Am 02.10.2013 19:31, schrieb Jeff Higgins: > On 10/02/2013 12:21 PM, Sebastian wrote: >> Am 02.10.2013 17:29, schrieb Jeff Higgins: >>> On 10/02/2013 03:33 AM, Sebastian wrote: >>>> Hello there, >>>> >>>> has anyone written about the relation of OO design patterns (by which I >>>> mean the usual GoF patterns) to functional programming idioms? >>>> >>> >>> relation+of+OO+design+patterns+to+functional+programming+idioms >>> >> >> I did Google a bit before posting, you know. One finds a couple of more >> or less incoherent discussions on blog posts, then one finds very >> theoretically-minded stuff that's sort of _inside_ FP. > > The subject has been widely bantered about. > Here's one discussion begun in 2008: > > > Here's a useful quote from Neal Ford's article series on IBM developerworks: In the functional-programming world, traditional design patterns generally manifest in one of three ways: 1. The pattern is absorbed by the language. 2. The pattern solution still exists in the functional paradigm, but the implementation details differ. 3. The solution is implemented using capabilities other languages or paradigms lack. (For example, many solutions that use metaprogramming are clean and elegant — and they're not possible in Java.) My reading so far could be summarized like this: - Strategy -- take functions (Java 8 lambdas) that implement a strategy -- provide functions to choose from - Template and Factory Method -- these patterns also relate to supplying concrete behavior -- abstract template methods may become simple members (lambdas), concrete subclasses disappear - Command -- disappears, because object wrapper not needed for portable functionality in Java 8 - Chain of Responsibility and Decorator -- composition of (partial) functions - Adaptor -- adaptor classes can be conveniently replaced by (composable) lambdas - Visitor - more complex, no direct correspondence - special case for streams: reduce (decouple traversal of stream from operation on stream elements) I’d welcome any comments, additional examples of correspondences etc. -- Sebastian