Here is my factory-method class.
public class AFactory : FactoryBase {
public override ProductBase ProduceProdut() {
return new SuperCoolProduct();
}
}
Here is my builder class.
public class ABuilder : BuilderBase {
ProductBase product = new SuperCoolProduct()
public override void BuildStep1() {
//Do Something (e.g. product.Add() )
}
public override void BuildStep2() {
//Do some more...(e.g. product.AddMore() )
}
public override ProductBase GetFinalProduct() {
return product;
}
}
My questions are the following ~
1) Does the builder has to expose some methods that the Director can call for compositing the product?
Can this class still be considered as a builder class? Or, Do we have to call it as a factory class? I think that we can’t call this class below as a builder anymore and it’s a factory class now..
public class ABuilder : BuilderBase {
ProductBase product = new SuperCoolProduct();
public override ProductBase GetFinalProduct() {
BuildStep1();
BuildStep2();
return product;
}
private void BuildStep1() {
//Do Something (e.g. product.Add() )
}
private void BuildStep2() {
//Do some more...(e.g. product.AddMore() )
}
}
2) Would the code below be a good example of combining “Builder” pattern and “Factory Method” pattern?
public class AFactory : FactoryBase {
BuilderBase builder;
public AFactory(BuilderBase builder){
this.builder = builder;
}
public override ProductBase ProduceProdut() {
this.builder.BuildStep1();
this.builder.BuildStep1();
return this.builder.GetFinalProduct();
}
}
As for factories: It’s more common to call the methods
CreateXXX