forked from steger/pr3-ws202627
49 lines
865 B
Go
49 lines
865 B
Go
package patterns
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type Noodle struct {
|
|
Type string
|
|
Name string
|
|
Length int
|
|
Girth int
|
|
}
|
|
|
|
type NoodleMaker struct {
|
|
noodle Noodle
|
|
}
|
|
|
|
func NewNoodleMaker() *NoodleMaker {
|
|
return &NoodleMaker{
|
|
noodle: Noodle{"Röhre", "Fusilli", 10, 5},
|
|
}
|
|
}
|
|
|
|
func (b *NoodleMaker) Length(l int) *NoodleMaker {
|
|
b.noodle.Length = l
|
|
return b
|
|
}
|
|
func (c *NoodleMaker) Girth(g int) *NoodleMaker {
|
|
c.noodle.Girth = g
|
|
return c
|
|
}
|
|
func (d *NoodleMaker) Name(n string) *NoodleMaker {
|
|
d.noodle.Name = n
|
|
return d
|
|
}
|
|
func (e *NoodleMaker) Type(t string) *NoodleMaker {
|
|
e.noodle.Type = t
|
|
return e
|
|
}
|
|
func (m *NoodleMaker) Build() (Noodle, error) {
|
|
if m.noodle.Length <= 0 {
|
|
return Noodle{}, errors.New("Länge muss größer als 0 sein")
|
|
}
|
|
if m.noodle.Girth <= 0 {
|
|
return Noodle{}, errors.New("Dicke muss größer als 0 sein")
|
|
}
|
|
return m.noodle, nil
|
|
}
|