Last active
August 29, 2015 14:20
-
-
Save dbuksbaum/d59d0726000f623c0114 to your computer and use it in GitHub Desktop.
Patterns 101 – Factory Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatorLEDTelevision : ITelevisionCreator | |
{ | |
public Television CreateTelevision() | |
{ | |
return new LED(); | |
} | |
} | |
class CreatorLCDTelevision : ITelevisionCreator | |
{ | |
public Television CreateTelevision() | |
{ | |
return new LCD(); | |
} | |
} | |
class CreatorPlasmaTelevision : ITelevisionCreator | |
{ | |
public Television CreateTelevision() | |
{ | |
return new Plasma(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Caliburn.Micro | |
{ | |
using System; | |
using System.Reflection; | |
using System.Windows; | |
/// <summary> | |
/// Represents the conventions for a particular element type. | |
/// </summary> | |
public class ElementConvention | |
{ | |
/// <summary> | |
/// The type of element to which the conventions apply. | |
/// </summary> | |
public Type ElementType; | |
/// <summary> | |
/// Gets the default property to be used in binding conventions. | |
/// </summary> | |
public Func<DependencyObject, DependencyProperty> GetBindableProperty; | |
/// <summary> | |
/// The default trigger to be used when wiring actions on this element. | |
/// </summary> | |
public Func<System.Windows.Interactivity.TriggerBase> CreateTrigger; | |
/// <summary> | |
/// The default property to be used for parameters of this type in actions. | |
/// </summary> | |
public string ParameterProperty; | |
/// <summary> | |
/// Applies custom conventions for elements of this type. | |
/// </summary> | |
/// <remarks>Pass the view model type, property path, property instance, framework element and its convention.</remarks> | |
public Func<Type, string, PropertyInfo, FrameworkElement, ElementConvention, bool> ApplyBinding = | |
(viewModelType, path, property, element, convention) => ConventionManager.SetBinding(viewModelType, path, property, element, convention); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ITelevisionCreator | |
{ | |
Television CreateTelevision(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LCD : Television | |
{ | |
} | |
class LED : Television | |
{ | |
} | |
class Plasma : Television | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Television | |
{ | |
private readonly string _typeName; | |
protected Television() | |
{ | |
_typeName = GetType().Name; | |
} | |
public void TurnOn() | |
{ | |
Console.WriteLine("Type == {0} Action == TurnOn()", _typeName); | |
} | |
public void TurnOff() | |
{ | |
Console.WriteLine("Type == {0} Action == TurnOff()", _typeName); | |
} | |
public void SetChannel(int channelNumber) | |
{ | |
Console.WriteLine("Type == {0} Action == SetChannel({1})", _typeName, channelNumber); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment