I am a beginner in design patterns.
I am trying to use Abstract Factory - pattern while maintaining Open-Closed Principle.
Plz look at the following code:
public interface IAbstractFormFactory
{
void ShowOSName();
}
public class VistaForm : IAbstractFormFactory
{
public void ShowOSName()
{
Console.WriteLine("Vista");
}
}
public class WinXpForm : IAbstractFormFactory
{
public void ShowOSName()
{
Console.WriteLine("Win XP");
}
}
public static class Application
{
public static void Run(IAbstractFormFactory factory)
{
factory.ShowOSName();
}
}
public class Program
{
public static void Main()
{
IAbstractFormFactory form;
int sys = 0;
if (sys == 0)
{
form = new WinXpForm();
}
else
{
form = new VistaForm();
}
Application.Run(form);
Console.ReadLine();
}
}
can it be an example of Abstract Factory Pattern?
If yes, how can I refactor it incorporating the concept of Open-Closed Principle?