tag:blogger.com,1999:blog-8110657754519829885.post2739115976194051939..comments2023-07-10T01:54:55.230-07:00Comments on GoLang Tutorials: Interfaces in Go - Part 2: Aiding adaptable, evolutionary designSathish VJhttp://www.blogger.com/profile/15718521031646368740noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-8110657754519829885.post-87509777630464283172016-08-18T01:16:17.692-07:002016-08-18T01:16:17.692-07:00but is it correct to assume, that every object tha...but is it correct to assume, that every object that can Write is a Writer ? maybe its Write has nothing at all with idea of Writer ?Anonymoushttps://www.blogger.com/profile/15530682268931004019noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-77529188116404264982015-01-06T08:25:00.893-08:002015-01-06T08:25:00.893-08:00"Embedding lets clients create augmented vers..."Embedding lets clients create augmented versions of things they don't own:<br /><br />type Bus {<br />their.Bus<br />}<br /><br />func (b Bus) blah() { ... }"<br /><br />Jacek, wouldn't this not work, because such a function definition would have to be located in the same package as Bus?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-70342599271779217212014-04-30T16:11:03.327-07:002014-04-30T16:11:03.327-07:00For this article specifically, one can write all t...For this article specifically, one can write all the rest of the code without defining the interfaces and the code will work the same. However, the author wrote this article to give example on how interfaces work and interact in Go. So, if you skip that the purpose will be lost :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-78079536981148637522013-10-29T03:37:43.470-07:002013-10-29T03:37:43.470-07:00From my understanding, (maybe it is slightly diffe...From my understanding, (maybe it is slightly different in Go but) Interface is like a C/C++ header file or a list of functions available in a binary Dynamic library. I mean it is for other programmers to see the list of functions available in your Program or Library or Module or whatever (you name it) etc. Imagine it is a closed source project. You only have to give other programmers a binary Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-47292230321574574492013-08-15T16:59:33.618-07:002013-08-15T16:59:33.618-07:00IMHO the benefits of interfaces are shown when the...IMHO the benefits of interfaces are shown when the program grows more complex, in the example above there's no immediate benefit that *bus* implements the interface *PublicTransporter*. But if you have a tank also, for example it would implement Cuboid but not PublicTransporter as it's not qualified for that. And for example if you need to print the passenger capacity of a vehicle, a Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-69493611391088249642013-08-04T16:37:14.593-07:002013-08-04T16:37:14.593-07:00In Java, interfaces are used due to the absence of...In Java, interfaces are used due to the absence of multiple inheritance. Since Go has multiple inheritance anyway, what's the point of interfaces?Jashhttps://www.blogger.com/profile/16381614310218706491noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-41021328645571571612013-03-17T13:05:40.973-07:002013-03-17T13:05:40.973-07:00I have to agree that defining an interface here be...I have to agree that defining an interface here besides good practice is a bit pointless. I would like to see how you use a design like this but instead of instantiating a bus Object and use it directly do polymorphism. E.g. pass the object to a function as a parameter (we don't care what object that is) and it will work as long as the object adheres to both Cuboider and PublicTransporter. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-90191339804191398002012-01-06T12:30:22.929-08:002012-01-06T12:30:22.929-08:00Hello Peter, I could direct you to my other first ...Hello Peter, I could direct you to my other first level Go Interfaces tutorial here: http://golangtutorials.blogspot.com/2011/06/interfaces-in-go.html, but that also assumes that you already know a little OOP. So based on your question, it looks like you are looking for a basic "need for interfaces" kind of topic. You could search for "OOP interface" and you'll find Sathish VJhttps://www.blogger.com/profile/15718521031646368740noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-53329730825406551982012-01-06T11:09:54.747-08:002012-01-06T11:09:54.747-08:00So in these examples you don't really need the...So in these examples you don't really need the interface declarations. Can you give a basic example of when you do need them, or where you can use them to achieve something that is more complex without an interface? This tutorial still doesn't tell me why an interface is useful.Peterhttp://pkleiweg.home.xs4all.nl/noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-63855903883971879862012-01-03T13:58:15.849-08:002012-01-03T13:58:15.849-08:00Embedding lets clients create augmented versions o...Embedding lets clients create augmented versions of things they don't own:<br /><br /> type Bus {<br /> their.Bus<br /> }<br /> <br /> func (b Bus) blah() { ... }Jacek Masiulaniechttps://www.blogger.com/profile/04906211249417384262noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-68350877154818784452012-01-03T08:56:53.117-08:002012-01-03T08:56:53.117-08:00Hello Chris, you are correct as far as one "c...Hello Chris, you are correct as far as one "cannot define new methods on non-local type", and one needs to make updates to the package. But this is different from changing the core classes. In larger projects a change to a central class has large ripple effects - developers will be nervous to ever touch something that has worked fairly ok until then :-). With Go one needs to update Sathish VJhttps://www.blogger.com/profile/15718521031646368740noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-87013482832919897292012-01-03T08:28:01.931-08:002012-01-03T08:28:01.931-08:00RE: "You have to convince whoever is in charg...RE: "You have to convince whoever is in charge of "class C" to add this interface to the implements list."<br /><br />Don't you still have to convince whoever is in charge of the package containing type Bus to add func (b Bus) IsCompliantWithLaw() bool {...} to the package?Chris Hineshttps://www.blogger.com/profile/05257336519292723803noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-88714723995124851022012-01-03T01:46:27.433-08:002012-01-03T01:46:27.433-08:00To address Paddie's question further: there is...To address Paddie's question further: there is no _actual_ need to specify the interface, until we need to give a type to an argument,etc. Even if not, they are useful documentation.<br /><br />It's an entertaining fact that (for instance) os.Error and fmt.Stringer are exactly compatible: they are just interfaces with a String() string method. A function that needs a Stringer will also Anonymoushttps://www.blogger.com/profile/08654958660870634908noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-35917272833691718702012-01-03T00:32:03.515-08:002012-01-03T00:32:03.515-08:00"Why is it you insist on defining the interfa..."Why is it you insist on defining the interfaces all the time? Couldn't you simply get away with just defining the bus-struct and then the methods that uses it?"<br /><br />Hello Paddie, what you are saying, though possible, would not illustrate what I intend to about the special feature of Go interfaces. <br />Yet this is not a forced example. In this design, our core data Sathish VJhttps://www.blogger.com/profile/15718521031646368740noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-31394286450870874382012-01-03T00:13:07.218-08:002012-01-03T00:13:07.218-08:00"Is there a reason why you did not call Cubic..."Is there a reason why you did not call CubicVolume or PassengerCapacity in IsCompliantWithLaw in your full code?"<br /><br />No there isn't, you could use the existing functions and get the same result.Sathish VJhttps://www.blogger.com/profile/15718521031646368740noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-77673336548391580712012-01-02T17:06:52.821-08:002012-01-02T17:06:52.821-08:00Why is it you insist on defining the interfaces al...Why is it you insist on defining the interfaces all the time? Couldn't you simply get away with just defining the bus-struct and then the methods that uses it?Paddiehttps://www.blogger.com/profile/10916912674591803495noreply@blogger.comtag:blogger.com,1999:blog-8110657754519829885.post-75796102009985206672012-01-02T17:00:38.061-08:002012-01-02T17:00:38.061-08:00Is there a reason why you did not call CubicVolume...Is there a reason why you did not call CubicVolume or PassengerCapacity in IsCompliantWithLaw in your full code?Anonymousnoreply@blogger.com