News for hackers. Stuff that matters.
Re:Why Go is elegant and makes my code elegant by NateDad on Saturday April 12, 2014 @08:45AM (#7577700)
The Factory abstracts away instantiation and configuration details for a complex or dynamic initialization process.

Is there some reason you can't do that by just having this?

  func IntializeFoo(f *foo)
The capability to define a function's return type to as an interface type would suggest otherwise

Uh... if you know what type the function is returning you, why do you need it to return an interface? You don't need the interface until you pass it into a function that requires an interface, at which time, the type you've made will be converted for you... why convert before you need to?

Either the consumer should never need to know about types, in which case, you should probably just make it an enum:

  type ServiceType int
  const (
      Weather ServiceType = iota
      News    ServiceType
  )

  type Service interface {}

  func Service(type ServiceType) Service

Or if the consumer should know about the service types for some reason, you can use the Initialize method above... or to genericize it better, and remove any need for the factory to know about concrete types:

  func Initialize(svc Service)
If you can avoid having both sides know about concrete types, it'll make your life a lot easier.

There are no comments on this comment yet.