C
CSharper
I have created a Factory pattern code. One thing I noticed after
coding, each factory has some methods they are exactly same and doing
the same code using the values specific to each factory, if I would
refactor the code and make it a seperate class and use the class in
each factory then the code look look and more DRY. My question is what
is the right way to do this in Factory Pattern. Refactoring them into
a seperate class is a solution? here is a sample code
public abstract class Fact
{
public void doit(int parm);
}
public sealed firstFact: Fact
{
int factValue = 10;
public override void doit(int parm)
{
dosomethingelse();
}
void dosomethingelse()
{
int t = factValue + 10;
}
}
public sealed secondFact: Fact
{
int factValue = 20;
public override void doit(int parm)
{
dosomethingelse();
}
void dosomethingelse()
{
int t = factValue + 10;
}
}
If you see the example above, the value of factValue changes based on
the factory you use. I over simplified the class for demo purpose. I
have bunch of more of facotroy specific values I need use.
Thanks
coding, each factory has some methods they are exactly same and doing
the same code using the values specific to each factory, if I would
refactor the code and make it a seperate class and use the class in
each factory then the code look look and more DRY. My question is what
is the right way to do this in Factory Pattern. Refactoring them into
a seperate class is a solution? here is a sample code
public abstract class Fact
{
public void doit(int parm);
}
public sealed firstFact: Fact
{
int factValue = 10;
public override void doit(int parm)
{
dosomethingelse();
}
void dosomethingelse()
{
int t = factValue + 10;
}
}
public sealed secondFact: Fact
{
int factValue = 20;
public override void doit(int parm)
{
dosomethingelse();
}
void dosomethingelse()
{
int t = factValue + 10;
}
}
If you see the example above, the value of factValue changes based on
the factory you use. I over simplified the class for demo purpose. I
have bunch of more of facotroy specific values I need use.
Thanks