On 26 April 2018 at 06:13,  <nimrod...@gmail.com> wrote:
> Hey everyone,
> I've encountered a design issue -
> I have an the following interface -
>
> type Runner interface {
>   Run(x X,y Y)
> }
>
> I want to add to it an Init(...) method which will initialize the internal
> fields of the Runner before performing `Run`..
> My issue is that different structs implementing the `Runner` interface
> require different fields in order to initialize, How should I solve this?

The conventional solution to this would be to avoid putting Init in
the Runner interface; instead you could have different factory
functions that each return a new appropriately initialised Runner
instance.

If you really need Init in there, one solution I've used in the past
is to have a uniform interface that involves initialization from
arbitrary data (in out case we used YAML, so each implementation knew
how to initialise itself from a YAML object). It all depends on the
constraints of your problem.

-- 
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.

Reply via email to