Slide 48
Slide 48 text
class UserStoryBuilder extends FactoryBuilderSupport {
UserStoryBuilder() {
registerFactory("story", new UserStoryFactory())
registerFactory("task", new TaskFactory())
registerFactory("finish", new TaskFinishFactory())
registerFactory("assignee", new UserFactory())
}
}
class UserStoryFactory extends AbstractFactory {
@Override
Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) throws
InstantiationException, IllegalAccessException {
def storyName = attributes.get("name", "Some Story")
def story = new UserStory(storyName)
def point = attributes.get("point", 1)
story.estimate(point)
story
}
@Override
void setChild(FactoryBuilderSupport builder, Object parent, Object child) {
def story = parent as UserStory
def task = child as Task
story.addTask(task)
}
}
Groovy標準ライブラリを
利用してBuilderを実装
(説明は割愛)
48