Hacker News new | ask | show | jobs
by maximilienandi 1917 days ago
Hello rustyboy, first thanks for your feedback.

I think that there is a mistake in the name of the interface type. It should not be `Cart` but something else. Like `CartStorage`.

A type that implement this CartStorage interface can be named `MySQLCartStorage` or `DynamoDBCartStorage`. Each database engine responsible for the storage will have a different implementation.

The interface is here to define a contract, a set of behaviors that you should implement.

I will definitely change that

1 comments

Let me just clarify, sorry i'm from python, so not very familiar but this feels like a "circular reference". You're implementing a struct CartStore which has methods GetById, and Put. Because interfaces (or contracts) are implicit then it's automatically considered a Cart.

What I don't understand is the return types of these functions, a pointer to a cart's cart member? or an error.

Interfaces in Go are implicitely implemented. It means that if a type has the methods defined in the interface, then it implements the interface.

I will update the example because it's confusing !

If you have some time come to the speak with me in the chatbox on the website I can help you understand this.

  cart.Cart
  package.NameInPackage
So the name Cart is an interface, the function/method signatures are indicating that a Cart is being returned but being explicit about the package the interface belongs to with cart.Cart. It's made more confusing since the name cart (lower-c) is being used for both a member variable and the package name in the signature of Put, and it looks like the package name doesn't show up on an explicit line in that chapter to help clarify it.