Here’s my proxy example with “func (a ProxyCar) Drive()” instead of 
DriveCar (I didn’t think this would work), and an F-150: 
https://play.golang.org/p/drDDkx_e0Mp

This may fix the signature difference but I see that having an interface 
type like you suggested for car would allow other data and methods that 
vary between cars to be held there. The original example from Wikipedia 
would probably need to be more complex to show a use case of the proxy 
pattern.

I think I see what you mean by this being more related to interceptor. My 
thought was the point was to add the additional behavior of checking for 
age on the ProxyCar type.

Thanks Josh.

Matt

On Friday, February 2, 2018 at 1:36:03 PM UTC-6, Joshua Humphries wrote:
>
> I didn't get a chance to look at all of them, but your Proxy pattern 
> example is incorrect.
>
> The idea of a proxy is that the proxy object exposes the same interface as 
> the underlying object, so they are substitutable. 
>
> In your example, Car is concrete (meaning that callers cannot substitute 
> any other type in its place). Also, the signature of the operation on Car 
> differs from the one on the Proxy that is meant to wrap it. Here's a fixed 
> version: https://play.golang.org/p/gq6Koi8f6XC
>
> I'll also pointed out that the example code -- which I see is 
> transliterated from the code snippets in Wikipedia -- likes more like its a 
> related pattern: the decorator (sometimes known as the interceptor pattern).
>
> ----
> *Josh Humphries*
> jh...@bluegosling.com <javascript:>
>
> On Fri, Feb 2, 2018 at 12:03 PM, <matthe...@gmail.com <javascript:>> 
> wrote:
>
>> I’m looking at patterns summarized on Wikipedia from “Design Patterns: 
>> Elements of Reusable Object-Oriented Software” and writing out a few as the 
>> equivalent in Go.
>>
>> Visitor: https://play.golang.org/p/A5tNzxMmetH
>>
>> Abstract Factory: https://play.golang.org/p/SWwuX49eysd
>>
>> Factory Method: https://play.golang.org/p/FRgDBx2CLFf
>>
>> Facade: https://play.golang.org/p/forPdwy9VCi
>>
>> Proxy: https://play.golang.org/p/DFWuDPTOzEP
>>
>> I’m curious how more experienced people rank these and the other patterns.
>>
>> Matt
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to