FAQ
It's hard to analyse because there is no business problem you are solving.
At the moment it's not clear what you gain from defining the interfaces
instead of using the concrete types. I would start by getting rid of all of
the interfaces, and then start to figure the best way to solve the business
problem and then add interfaces as necessary.

+ Egon
On Monday, 9 May 2016 15:19:08 UTC+3, GoNutter wrote:

Hi All,

I have developed a http client for an GetEventStore

On the client there are several methods. I wanted to use interfaces to
describe the API and I think I have done it in line with good practice. the
interfaces are small as shown below.
type StreamAppender interface {
AppendToStream(string, *StreamVersion, ...*Event) (*Response, error)
}


type MetaDataUpdater interface {
UpdateStreamMetaData(string, interface{}) (*Response, error)
}


type MetaDataReader interface {
GetStreamMetaData(string) (*EventResponse, *Response, error)
}


type StreamReader interface {
ReadStreamForward(string, *StreamVersion, *Take) ([]*EventResponse, *
Response, error)
ReadStreamBackward(string, *StreamVersion, *Take) ([]*EventResponse, *
Response, error)
}


type StreamReaderAsync interface {
ReadStreamForwardAsync(string, *StreamVersion, *Take) <-chan struct {
*EventResponse
*Response
error
}
ReadStreamBackwardAsync(string, *StreamVersion, *Take) <-chan struct {
*EventResponse
*Response
error
}
}


type EventBuilder interface {
ToEventData(string, string, interface{}, interface{}) *Event
}


type EventReader interface {
GetEvent(string) (*EventResponse, *Response, error)
GetEvents([]string) ([]*EventResponse, *Response, error)
}

Now this helps becasue I can now inject fakes of the client into my client
code which uses the eventstore client. The constructor on the client code
now looks like this...

type GetEventStore struct {
eventBus EventBus
eventFactory EventFactory
appender goes.StreamAppender
builder goes.EventBuilder
reader goes.StreamReader
}


func NewGetEventStore(
eventBus EventBus,
appender goes.StreamAppender,
builder goes.EventBuilder,
reader goes.StreamReader) *GetEventStore {

s := &GetEventStore{
eventBus: eventBus,
appender: appender,
builder: builder,
reader: reader,
}

return s
}


So far so good, however the wierdness comes with the code injecting the
eventstore into this constructor... it looks like this..

client := goes.NewClient(nil, eventStoreURL)
eventStore := ycq.NewGetEventStore(eventBus, client, client, client)


It feels weird to be passing the same object three times to the
constructor. Does this feel weird to anyone else or is this something I
should just get over because in every other respect it feels like the right
thing to do.

Many thanks
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 12 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 9, '16 at 12:06p
activeMay 10, '16 at 12:48p
posts12
users3
websitegolang.org

3 users in discussion

GoNutter: 7 posts Egon: 4 posts Jan Mercl: 1 post

People

Translate

site design / logo © 2021 Grokbase