Logo

Programming-Idioms

History of Idiom 73 > diff from v320 to v321

Edit summary for version 321 by programming-idioms.org:
[Go] pFact -> fact

Version 320

2016-06-12, 16:49:45

Version 321

2016-06-12, 16:52:09

Idiom #73 Create a factory

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Idiom #73 Create a factory

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Code
type ParentFactory func(string) Parent

var pFact ParentFactory = func(str string) Parent {
	return Parent{
		name: str,
	}
}
Code
type ParentFactory func(string) Parent

var fact ParentFactory = func(str string) Parent {
	return Parent{
		name: str,
	}
}
Comments bubble
A Factory is a function which returns an object.

Go doesn't have subtyping, but Parent could be any type: struct, interface, etc.
Comments bubble
A Factory is a function which returns an object.

Go doesn't have subtyping, but Parent could be any type: struct, interface, etc.
Demo URL
http://play.golang.org/p/6pE8ijPdWu
Demo URL
https://play.golang.org/p/GLu7zxLi3T