Skip to main content

Posts

Showing posts from 2014

Design Patterns - Abstract Factory Pattern

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DesignPattern_AbstractFactoryApp {    class Program    {       static void Main( string [] args)       {          /* ABSTRACT FACTORY PATTERN:           * The abstract factory pattern provides a way to            * encapsulate a group of individual factories            * that have a common theme without            * specifying their concrete classes.           * Use of this pattern makes it possible to            * interchange concrete implementations            * without changing the code            * that uses them, even at runtime.            * However, employment of this pattern,            * as with similar design patterns,            * may result in unnecessary complexity            * and extra work in the initial writing of code           */          var samsungSmartPhone = new GenericFac

Design Patterns - Strategy Pattern

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DesignPattern_StrategyPattern {    class Program    {       static void Main( string [] args)       {          /* STRATEGY PATTERN (POLICY PATTERN):           * Strategy lets the algorithm vary independently            * from clients that use it.           * When the program is running, we can switch between different            * type of algorithms           * For instance, a class that performs validation on incoming data           * may use a strategy pattern to select a validation            * algorithm   based on the type of data,            * the source of the data, user choice,           * or other discriminating factors. These factors are not known            * for each case   until run-time, and may require            * radically different validation to be performed.           */           ICalcu