Im so confused about what is the actual difference between abstract factory pattern and factory pattern. I had gone through this Stackoverflow reference question but couldn't reach in a conclusion.
public abstract class AnimalFactory
{
public abstract Animal CreateFish();
public abstract Animal CreateBird();
public abstract Animal CreateMammal();
}
public class AfricanAnimalFactory : AnimalFactory
{
public override Animal CreateFish()
{
return new Reedfish();
}
public override Animal CreateBird();
{
return new Flamingo();
}
public override Animal CreateMammal();
{
return new Lion();
}
}
As per the example given, can the below code be shown as factory pattern?
public abstract class AnimalFactory
{
public abstract Animal CreateFish();
}
public class AfricanAnimalFactory : AnimalFactory
{
public override Animal CreateFish()
{
return new Reedfish();
}
}
I had seen many questions which have been answered theoretically. im looking for a code wise explanation on this.
Aucun commentaire:
Enregistrer un commentaire