Wednesday, May 1, 2013

Published 11:14 PM by with 1 comment

Factory Pattern - [Creational Patterns]



Factory Pattern

Logical Model

As with other design patterns, there are countless variations of the Factory pattern, although most variants typically used the same set of primary actors, a client, a factory, and a product. The client is an object that requires an instance of another object (the product) for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. Bellow shows this logical relationship between these elements of the pattern.





abstract class Page
{
}

class Education : Page
{
}

class SkillPage : Page
{
}

class Experiance : Page
{
}

//----
abstract class Document
{
private List<Page> _pages = new List<Page>();

        public abstract void CreatePages();

        public Document()
        {
            this.CreatePages();
        }

        public List<Page> Page
        {
            get { return _pages; }
        }
    }

class Resume : Document
{
   public override void CreatePages()
   {
Page.Add(new Education());
       Page.Add(new SkillPage());
       Page.Add(new Experiance());
   }
}

 

    email this       edit

1 comments:

Aruna Jayathilaka said...

Ref:http://msdn.microsoft.com/en-us/library/ee817667.aspx