Here is the code shown as below:
package main
import "fmt"
//concrete shape
type Shape struct {
draw string
}
//abstract factory for creating shape
type AbstractFactory interface {
CreateShape() Shape
}
type CubeFactory struct {
}
type CircleFactory struct {
}
//concrete implementation
func (a CubeFactory) CreateShape() Shape {
return Shape{"Cube"}
}
//concrete implementation
func (a CircleFactory) CreateShape() Shape {
return Shape{"Circle"}
}
//main factory method
func getShape(typeGf string) Shape {
var gffact AbstractFactory
switch typeGf {
case "cube":
gffact = CubeFactory{}
return gffact.CreateShape()
case "circle":
gffact = CircleFactory{}
return gffact.CreateShape()
}
return Shape{}
}
func main() {
a := getShape("cube")
fmt.Println(a.draw)
}
Other Topics:
How to build NGINX RTMP module, Setup Live Streaming with NGINX RTMP module, Publishing Stream with Open Broadcaster Software (OBS), Create Adaptive Streaming with NGINX RTMP, Implementing Filtergraph in Streaming with NGINX RTMP, How to Implement Running Text in Streaming with NGINX RTMP, How to build OpenSceneGraph with Code::Blocks, How to build OpenSceneGraph with Visual Studio 2010, Building Geometry Model, How to run OpenSceneGraph with Netbean IDE 8.2 C++, Rendering Basic Shapes, Using OSG Node to Load 3D Object Model, Rendering 3D Simulator with OpenSceneGraph, How to compile wxWidgets with Visual Studio 2010, How to Setup Debugging in Golang with Visual Code
No comments:
Post a Comment