Skip to content

Instantly share code, notes, and snippets.

@rbwestmoreland
rbwestmoreland / IFactory.cs
Created December 11, 2011 16:30
Properly Implementing the Factory Pattern
using System;
/// <summary>
/// A generic factory pattern.
/// <para>The Factory pattern is a creational pattern,
/// whose purpose is to define an interface for
/// creating an object, but let subclasses decide
/// which class to instantiate.</para>
/// </summary>
/// <typeparam name="T">The type created by the factory.</typeparam>
@rbwestmoreland
rbwestmoreland / NuGet Package Automation Post-Build Event
Created December 11, 2011 17:00
NuGet package automation using a Visual Studio post-build event
if $(ConfigurationName) == Release "$(SolutionDir)packages\NuGet.CommandLine.1.5.21005.9019\tools\NuGet.exe" pack "$(ProjectPath)" -Properties Configuration=Release -Verbose
@rbwestmoreland
rbwestmoreland / Dispose.cs
Created December 13, 2011 01:58
Properly Implementing the Dispose Pattern
using System;
/// <summary>
/// An example Dispose pattern.
/// <para>The Dispose pattern is a design pattern, whose
/// purpose is to handle resource cleanup in runtime
/// environments that use automatic garbage collection.</para>
/// </summary>
public class YourClass : IDisposable
{
@rbwestmoreland
rbwestmoreland / Observer.cs
Created December 13, 2011 02:24
Properly Implementing the Observer Pattern
using System;
using System.Collections.Generic;
/// <summary>
/// An example Observer pattern.
/// <para>The Observer pattern is a behavioral
/// pattern, whose purpose is to define a one-to-many
/// dependency between objects where a state change
/// in one object results with all its dependents
/// being notified and updated automatically.</para>
@rbwestmoreland
rbwestmoreland / AndSpecification.cs
Created December 18, 2011 03:13
Properly Implementing the Specification Pattern
using System;
internal class AndSpecification<T> : ISpecification<T>
{
private ISpecification<T> Specification1 { get; set; }
private ISpecification<T> Specification2 { get; set; }
internal AndSpecification(ISpecification<T> s1, ISpecification<T> s2)
{
Specification1 = s1;
@rbwestmoreland
rbwestmoreland / IAbstractFactory.cs
Created December 29, 2011 14:57
Properly Implementing the Abstracy Factory Pattern
using System;
/// <summary>
/// An example abstract factory interface.
/// <para>The Abstract Factory pattern is a creational
/// pattern, whose purpose is to provide an interface
/// for creating families of related or dependent
/// objects, without specifying their concrete
/// classes.</para>
/// </summary>
@rbwestmoreland
rbwestmoreland / ActualToExpectedAdapter.cs
Created December 29, 2011 15:41
Properly Implementing the Adapter Pattern
using System;
/// <summary>
/// An actual to expected adapter.
/// <para>The Adapter pattern is a structural pattern,
/// whose purpose is to convert the interface of a class
/// into another interface clients expect.</para>
/// </summary>
public class ActualToExpectedAdapter : IExpected
{
@rbwestmoreland
rbwestmoreland / BaseDecorator.cs
Created December 29, 2011 16:38
Properly Implementing the Decorator Pattern
using System;
/// <summary>
/// The object which adds responsibilities to
/// a base instance.
/// <para>The Decorator pattern is a structural pattern, whose
/// purpose is to attach additional responsibilities to
/// an object dynamically keeping the same interface. </para>
/// </summary>
public class BaseDecorator : IBase
@rbwestmoreland
rbwestmoreland / ConcreteObject.cs
Created December 30, 2011 16:10
Properly Implementing the Proxy Pattern
using System;
/// <summary>
/// The actual object.
/// </summary>
public class ConcreteObject : IObject
{
public void DoWork()
{
}
@rbwestmoreland
rbwestmoreland / Facade.cs
Created January 8, 2012 20:34
Properly Implementing the Facade Pattern
using System;
/// <summary>
/// The object which delegates to the appropriate sub-system.
/// <para>The Facade pattern is a structural pattern, whose
/// purpose is to provide a unified interface to a set of
/// interfaces in a subsystem.</para>
/// </summary>
public class Facade
{