Skip to content

Commit

Permalink
feat(factory): update abstract factory (#9)
Browse files Browse the repository at this point in the history
* add more for abstract factory

* update
  • Loading branch information
shanghai-Jerry authored Jan 30, 2024
1 parent 78c39f3 commit c42a47d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 02_factory/023_abstract_factory/abstract_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,38 @@ func (j jsonConfigParserFactory) CreateRuleParser() IRuleConfigParser {
func (j jsonConfigParserFactory) CreateSystemParser() ISystemConfigParser {
return jsonSystemConfigParser{}
}

type yamlConfigParserFactory struct{}

func (y yamlConfigParserFactory) CreateRuleParser() IRuleConfigParser {
return yamlRuleConfigParser{}
}

func (y yamlConfigParserFactory) CreateSystemParser() ISystemConfigParser {
return yamlSystemConfigParser{}
}

type yamlRuleConfigParser struct{}

func (y yamlRuleConfigParser) Parse(data []byte) {
panic("implement me")
}

type yamlSystemConfigParser struct{}

func (y yamlSystemConfigParser) ParseSystem(data []byte) {
panic("implement me")
}

// NewIConfigParserFactory ...
// 抽象工厂基于工厂方法,用一个简单工厂封装工厂方法
// 只不过一个工厂方法可创建多个相关的类
func NewIConfigParserFactory(t string) IConfigParserFactory {
switch t {
case "json":
return jsonConfigParserFactory{}
case "yaml":
return yamlConfigParserFactory{}
}
return nil
}

0 comments on commit c42a47d

Please sign in to comment.