Quantcast
Channel: How to write idiomatic constructor - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by OlegI for How to write idiomatic constructor

It depends a bit on your preference and how you view things. Coming from OOP background my take is: there is no point in the constructor if you cannot enforce it. Adding the constructor means - you...

View Article



Answer by Adirio for How to write idiomatic constructor

As it has already been mentioned, returning an interface should be considered something exceptional.Returning errors of type error which is an interface is one of those exception.Returning an interface...

View Article

Answer by Gaurav Dhiman for How to write idiomatic constructor

In most cases constructor functions return concrete types (or pointer to a type).The situations in which returning interfaces might be a good idea is when calling factory functions or builder functions...

View Article

How to write idiomatic constructor

I'm confused about the constructors in Go. Most constructors I've seen return a struct, but 'Effective Go' suggests that an interface can be returned in some cases, according to the rule of...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>