using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FactoryDesignPattern
{
interface IProgramingLanguages
{
string ProgramingLanguage
{ get; }
}
class C : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to C Language";
}
}
}
class CPlusPlus : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to C++ Language";
}
}
}
class CSharp : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to C# Language";
}
}
}
class Java : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to Java Language";
}
}
}
class JavaScript : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to JavaScript Language";
}
}
}
class PHP : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to PHP Language";
}
}
}
class Python : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to Python Language";
}
}
}
class Ruby : IProgramingLanguages
{
public string ProgramingLanguage
{
get
{
return "Welcome
to Ruby Language";
}
}
}
static class Factory
{
public static IProgramingLanguages GetLanguage(string language)
{
switch (language)
{
case "C":
return new C();
break;
case "C++":
return new CPlusPlus();
break;
case "C#":
return new CSharp();
break;
case "Java":
return new Java();
break;
case "JavaScript":
return new JavaScript();
break;
case "PHP":
return new PHP();
break;
case "Python":
return new Python();
break;
case "Ruby":
return new Ruby();
break;
default:
throw new ApplicationException(string.Format("{0}
Class is missing.", language));
}
}
}
class Program
{
static void Main(string[]
args)
{
IProgramingLanguages obj
= Factory.GetLanguage("C#");
Console.WriteLine(obj.ProgramingLanguage);
Console.ReadKey();
}
}
}
Output
Welcome to C# Language
For More Details
Visit Microsoft.com
No comments:
Post a Comment