New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dao Interface #725
Dao Interface #725
Conversation
|
This has been on the agenda for a long time. Glad to see it finally. EDIT: I coined the term DAO, but kind of hate it? Can anyone think of a better name for this? It's more of a Data Access Layer (DAL?) This PR would be the time to change it, if desired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a big fan of using an interface where there is a dependency. As I mentioned in the issue linked here, it will help with writing unit tests. So I am delighted that we are making this change.
Couple of personal preferences and thoughts
I think it would be good over time to split up this large interface into a set of smaller interfaces based around distinct capabilities. The reason for this is two fold
- It allows for better encapsulation. Perhaps some areas only care about ServiceInstances and shouldn't know about ServiceBindings
- Allows for simpler mocking. We will need to implement all of these methods in a mock to perhaps only enable a test that uses one of the methods
On another note. I think it is a good idea for the consumer package to define the interface rather than the provider. This can help avoid dependency issues (circular dependencies for example) as the consumer package does not directly depend on the provider package instead the consumer provides the interface it expects and this is fulfilled by the provider.
|
@maleck13 Sorry I am not fully following your recommendation regarding interfaces. What I am seeing is Is that different then what you are referring to? (edit: hit comment too quickly) I think that an evaluation of this interface is a good idea as well. I would not mind breaking up dao into littler interfaces like such type Dao interface {
SpecDAO
...
}
type SpecDAO interface {
GetSpec(string) (apb.Spec, error)
....
}@eriknelson regarding the name. I can't think of anything that is significantly better the DAO. I also would love something better though 😄 |
|
Sorry @shawn-hurley I will give a more concrete example of what I mean. The broker package depends on the DAO. So in my suggestion the broker package would now define the interface that it needs as it knows its requirements best and so would no longer depend on |
|
Ah ok, that does make more sense now thank you. I would like to hear more about that helps prevent circular dependencies. |
|
|
||
| return specs, nil | ||
| func NewDao() (Dao, error) { | ||
| return etcd.NewDao() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea we'll have multiples from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that was the initial plan/thought process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
|
@eriknelson @shawn-hurley as far as names, the only thing that is descriptive is DAL since it is a data access layer vs DAO which usually means data access object. |
|
@eriknelson @shawn-hurley correction I do have a name suggestion: AXON http://www.dictionary.com/browse/axon
|
|
Are we holding off because of naming? or are we good? |
|
@shawn-hurley hope this is an interesting discussion ( I think so) but not my intention to hijack the PR :)
Standard Lib: On the circular dependencies: (this really is less of a thing but a side benefit) |
Describe what this PR does and why we need it:
Having an interface for the DAO will allow us to switch persistent layers. This will also allow for unit testing in other parts of the code base.
Changes proposed in this pull request
Does this PR depend on another PR (Use this to track when PRs should be merged)
depends-on
fix for PR #722 Work Item 1
Which issue this PR fixes (This will close that issue when PR gets merged)
This fixes #542