tag:blogger.com,1999:blog-36547168.post2289799292601515755..comments2023-11-25T11:00:42.257+01:00Comments on Invisible to the eye: Practical Php Patterns: AdapterGiorgiohttp://www.blogger.com/profile/03558287012747987157noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-36547168.post-75811701168402975352011-02-08T20:54:13.132+01:002011-02-08T20:54:13.132+01:00Got it! Thanks!Got it! Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-66876366252731605492010-02-08T07:56:23.432+01:002010-02-08T07:56:23.432+01:00What a great resource!What a great resource!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-36547168.post-73249229408080290662010-01-16T11:23:37.460+01:002010-01-16T11:23:37.460+01:00I think they can be considered different Strategie...I think they can be considered different Strategies but, that said, some of them fall in the Adapter's intent.<br />Consider the Zend_Paginator_Adapter_Iterator: it is really a wrapper around an Iterator to modify its interface. Most of the Adapter-named classes in Zend_Framework uses other components' classes to achieve their goal, and it seems to me they are better named as Adapters. Strategies were originally thought as Flyweight objects, not as full-fledged objects with collaborators.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-54133379080534553672010-01-16T06:12:59.025+01:002010-01-16T06:12:59.025+01:00What's your take on the difference between the...What's your take on the difference between the Adapter and Strategy patterns? My understanding is that they are very similar, and the main difference is really intent. A strategy is for swapping in different kinds of behavior. The adapter is the same basic idea but it's purpose is specifically for wrapping an implementation that is already close to what you need, but just needs its interface tweaked. <br /><br />I bring this up because of your choice to use Zend_Paginator as an example. It's something that has bothered me about the naming in many Zend Framework components. Why is Zend_Paginator_Adapter_Interface named an "adapter"? For it to be an adapter it should adapt something. The implementations of the Zend_Paginator_Adapter_Interface are full-fleged implementations of different paginating strategies, not just wrappers around existing paginating implementations (i.e. 3rd party paginators). Are these not just examples of the Strategy pattern?<br /><br /><a href="http://stackoverflow.com/questions/1185441/zendauth-why-authenticate-object-named-adapter-and-not-strategy" rel="nofollow">Someone else asks the same question.</a><br /><br />P.S. I just discovered your blog a couple months ago and it has become one of my favorite sources for high-quality writing on software development with php. Keep up the great work!Dell Salahttps://www.blogger.com/profile/15103106354831184190noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-48410362271879224072010-01-15T17:27:52.776+01:002010-01-15T17:27:52.776+01:00The difference may be subtle, but I usually think ...The difference may be subtle, but I usually think of 3rd party libraries as wrapped in a Facade instead of a Adapter.Giorgiohttps://www.blogger.com/profile/12689416577856305650noreply@blogger.comtag:blogger.com,1999:blog-36547168.post-35841908645039147812010-01-15T14:08:41.554+01:002010-01-15T14:08:41.554+01:00For your last paragraph: you frequently use the Ad...For your last paragraph: you frequently use the Adapter pattern to adapt away 3rd party APIs from your code, so that you don't have to mock up said API in the tests. Mocking up large interfaces is hard work, so that's another argument to reinforce the notion of keeping Target small and cohesive.fqqdkhttps://www.blogger.com/profile/17736847701391219927noreply@blogger.com