Skip to main content

Posts

Showing posts from June, 2012

VBA versus .NET

Factory Method

Following is an example of the Factory Method.  In this case, a method call sets and returns the type.  Also, pardon the values set as field, rather than as properties, but this is a simple example, rather than a full implementation. Salient Point(s) A hidden constructor Each class  method instantiates the class differently. Code using System; namespace DesignPatterns {        //primary class for factory method     public class FactoryObject     {         //public fields, set as part of method and return         public int X;         public int Y;         public int Result;         //factory method         public FactoryObject Addition(int x, int y)         {             return new FactoryObject(x, y, x + y);         }         //factory method         public FactoryObject Subtaction(int x, int y)         {             return new FactoryObject(x, y, x - y);         }         //factory method         public FactoryObject Multiplication(int x, int y)

Design Patterns

I expect to present code for a variety of design patterns, for my own edification, many of I which already use in production applications. The original source:   http://en.wikipedia.org/wiki/Design_Patterns   Below is a list compiled from other sources, unattributed: Pattern Type Name Description Creational Abstract factory Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Factory method Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Builder Separate the construction of a complex object from its representation so that the same construction process can create different representations. Lazy initialization Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the fi