Interfaces are not for grouping variable behavior, interfaces are for allowing generic code to apply to varying data structures.
Consider a struct of function fields for grouping variable behavior without a backing data structure. If your interface type is not an input in the same package then you didn’t need an interface. I’m not convinced these three types should be interfaces. Matt On Tuesday, March 13, 2018 at 1:06:23 AM UTC-5, Reinhard Luediger wrote: > > Dear all, > > as far as I know it is recommended to keep actual interfaces as small as > possible and to form bigger interfaces via interface composiston. > Would be great if the community could advise me what the real benefits are. > > Lets say i want to create an interface for the database backend like the > following example. > > //CleanupTimestamps is the interface which holds all methods related to > cleanupTimestamps > type CleanupTimestamps interface { > SaveCleanupTimeStamp(taskName string, timestamp time.Time) (err error) > GetCleanupTimeStamp(taskName string) (timestamp *time.Time, err error) > } > > //ClusterFlavors interface holds all methods related to clusterFlavor > type ClusterFlavors interface { > CreateClusterFlavor(Name string, tx StoreTransaction) (Flavor > datatypes.ClusterFlavorPersisted, err error) > UpdateClusterFlavor(ID string, Name string, tx StoreTransaction) (err > error) > MarkClusterFlavorDeleted(ID string, tx StoreTransaction) (err error) > DeleteClusterFlavorPermanent(ID string, tx StoreTransaction) (err error) > ReadClusterFlavor(ID string) (Flavor datatypes.ClusterFlavorPersisted, err > error) > ListClusterFlavors(Includedeleted bool) (Flavors > []datatypes.ClusterFlavorPersisted, err error) > } > > //Store is the interface to encapsulate the Storage Backend > type Store interface { > MustBegin() (tx StoreTransaction) > > CleanupTimestamps > ClusterFlavors > } > > > Why should I create it in that fashion if I ever use the Store interface > in my cod? Or what are the drawbacks if I put all methods needed directly > into the Store interface? > > kind regards > > Reinhard > > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.