Where should we define Go interface in multiple Consumer scenario ? What about interface in producer to show...











up vote
0
down vote

favorite












Can someone give me a concrete example to this advise ?
https://github.com/golang/go/wiki/CodeReviewComments#interfaces
TLDR;



So is this how i follow it ?



package worker

type interface DB {
getAllTable()
}


type worker struct {
db DB
}

func (w worker) doSomething() {
w.db.getAllTable()
}




package listener

type interface DB {
getAllTable()
}

type listener struct {
db DB
}

func (l listener) doSomething() {
l.db.getAllTable()
}




package msql

type mysql struct {}

func (mysql) getAllTable() {
}


Is it alright to duplicate the interfaces in 2 places to satisfy ‘define consumer where it is consumed’.





What about using interface to show generality ? It’s defining interface not where it is consumed



For example hash/crc32 and hash/adler32 implementing hash.Hash32










share|improve this question







New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 days ago










  • Furthermore, you need to post real code, not a generalized example. See How to Ask.
    – 200_success
    2 days ago















up vote
0
down vote

favorite












Can someone give me a concrete example to this advise ?
https://github.com/golang/go/wiki/CodeReviewComments#interfaces
TLDR;



So is this how i follow it ?



package worker

type interface DB {
getAllTable()
}


type worker struct {
db DB
}

func (w worker) doSomething() {
w.db.getAllTable()
}




package listener

type interface DB {
getAllTable()
}

type listener struct {
db DB
}

func (l listener) doSomething() {
l.db.getAllTable()
}




package msql

type mysql struct {}

func (mysql) getAllTable() {
}


Is it alright to duplicate the interfaces in 2 places to satisfy ‘define consumer where it is consumed’.





What about using interface to show generality ? It’s defining interface not where it is consumed



For example hash/crc32 and hash/adler32 implementing hash.Hash32










share|improve this question







New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 days ago










  • Furthermore, you need to post real code, not a generalized example. See How to Ask.
    – 200_success
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Can someone give me a concrete example to this advise ?
https://github.com/golang/go/wiki/CodeReviewComments#interfaces
TLDR;



So is this how i follow it ?



package worker

type interface DB {
getAllTable()
}


type worker struct {
db DB
}

func (w worker) doSomething() {
w.db.getAllTable()
}




package listener

type interface DB {
getAllTable()
}

type listener struct {
db DB
}

func (l listener) doSomething() {
l.db.getAllTable()
}




package msql

type mysql struct {}

func (mysql) getAllTable() {
}


Is it alright to duplicate the interfaces in 2 places to satisfy ‘define consumer where it is consumed’.





What about using interface to show generality ? It’s defining interface not where it is consumed



For example hash/crc32 and hash/adler32 implementing hash.Hash32










share|improve this question







New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Can someone give me a concrete example to this advise ?
https://github.com/golang/go/wiki/CodeReviewComments#interfaces
TLDR;



So is this how i follow it ?



package worker

type interface DB {
getAllTable()
}


type worker struct {
db DB
}

func (w worker) doSomething() {
w.db.getAllTable()
}




package listener

type interface DB {
getAllTable()
}

type listener struct {
db DB
}

func (l listener) doSomething() {
l.db.getAllTable()
}




package msql

type mysql struct {}

func (mysql) getAllTable() {
}


Is it alright to duplicate the interfaces in 2 places to satisfy ‘define consumer where it is consumed’.





What about using interface to show generality ? It’s defining interface not where it is consumed



For example hash/crc32 and hash/adler32 implementing hash.Hash32







go interface solidity






share|improve this question







New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









despacito2012

6




6




New contributor




despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






despacito2012 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Martin R, Toby Speight, VisualMelon, 200_success, Sᴀᴍ Onᴇᴌᴀ

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 3




    The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 days ago










  • Furthermore, you need to post real code, not a generalized example. See How to Ask.
    – 200_success
    2 days ago














  • 3




    The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 days ago










  • Furthermore, you need to post real code, not a generalized example. See How to Ask.
    – 200_success
    2 days ago








3




3




The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
2 days ago




The current question title, which states your concerns about the code, is too general to be useful here. Please edit to the site standard, which is for the title to simply state the task accomplished by the code. Please see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
2 days ago












Furthermore, you need to post real code, not a generalized example. See How to Ask.
– 200_success
2 days ago




Furthermore, you need to post real code, not a generalized example. See How to Ask.
– 200_success
2 days ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Mont Emei

Province de Neuquén

Journaliste