c# - Factory Pattern, Another Pattern or no pattern at all? -


i have 2 cases wheter method can considered factory design pattern, example in c#, altought, can apply other programming languages:

enum ninjatypes {   generic,   katanna,   starthrower,   invisible,   flyer }  public class ninja {   public string name { get; set; }   public void jump() { ... }   public void kickass() { ... } }  public class katannaninja: ninja {   public void usekatanna() { ... } }  public class starninja: ninja {   public void throwstar() { ... } }  public class invisibleninja: ninja {   public void becomeinvisible() {...}   public void becomevisible() {...} }  public class flyninja: ninja {   public void fly() {...}   public void land() {...} }  public class ninjaschool {   // return generic type   public ninja standardstudent() {...}   // may return other types   public ninja specialitystudent(ninjatypes whichtype) {...} } 

the method standardstudent() return new object of same type, specialitystudent(...), may return new objects different classes share same superclass / base type. both methods intentionally not virtual.

the question is, both methods "factory design pattern" ?

my guess specialitystudent(...) is, standardstudent() not. if second not, can considered design pattern ?

i don't think nor factorymethod`nor abstractfactory patterns forbid user use parameter specify type creator method. anyway should consider @ least 2 things in design:

  1. factory methods useful keep client unaware of concrete type of created object. point of view isn't wrong specify explicitly type of object created, pay attention not put knowledge on client classes able construct objects through factory.
  2. both factory methods return ninja object, of ninjas extended class declare additional methods, client unaware of. if client need use methods explicitly maybe have make consideration on design.

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -