Here’s my proxy example with “func (a ProxyCar) Drive()” instead of
DriveCar (I didn’t think this would work), and an F-150:
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
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.
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*
>> 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.
>> 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
>> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.