Skip to content

Instantly share code, notes, and snippets.

@aliozgur
Created May 21, 2018 16:29
Show Gist options
  • Save aliozgur/91a969449174b041cfc3637bfc8a72eb to your computer and use it in GitHub Desktop.
Save aliozgur/91a969449174b041cfc3637bfc8a72eb to your computer and use it in GitHub Desktop.
GoF-Abstract Factory
using System;
namespace GofFactory_Revisited
{
public enum PlatformType
{
Mobile,
Desktop
}
interface IDrawable
{
void Draw();
}
interface IStatusBar:IDrawable
{
void AddButton(IButton button);
}
interface IButton:IDrawable
{
string Caption { get; set; }
}
class DesktopButton : IButton
{
public string Caption { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void Draw()
{
//
}
}
class MobileButton : IButton
{
public string Caption { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void Draw()
{
throw new NotImplementedException();
}
}
class MobileStatusBar : IStatusBar
{
public void AddButton(IButton button)
{
throw new NotImplementedException();
}
public void Draw()
{
throw new NotImplementedException();
}
}
class DesktopStatusBar : IStatusBar
{
public void AddButton(IButton button)
{
throw new NotImplementedException();
}
public void Draw()
{
throw new NotImplementedException();
}
}
interface IGuiFactory
{
IButton GetButton();
IStatusBar GetStatusBar();
}
class DesktopGuiFactory : IGuiFactory
{
public IButton GetButton()
{
return new DesktopButton();
}
public IStatusBar GetStatusBar()
{
return new DesktopStatusBar();
}
}
class MobileGuiFactory : IGuiFactory
{
public IButton GetButton()
{
return new MobileButton();
}
public IStatusBar GetStatusBar()
{
return new MobileStatusBar();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment