<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Avsarang</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Avsarang"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Avsarang"/>
	<updated>2026-07-14T05:46:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML.png&amp;diff=68034</id>
		<title>File:UML.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML.png&amp;diff=68034"/>
		<updated>2012-10-23T19:01:01Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68033</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68033"/>
		<updated>2012-10-23T19:00:39Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Headline text */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML Diagram ==&lt;br /&gt;
[[File:UML.png]]&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68032</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68032"/>
		<updated>2012-10-23T19:00:15Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Headline text ==&lt;br /&gt;
UML Diagram&lt;br /&gt;
[[File:UML.png]]&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68031</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68031"/>
		<updated>2012-10-23T18:59:33Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Headline text ==&lt;br /&gt;
UML Diagram&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68030</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68030"/>
		<updated>2012-10-23T18:58:52Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* UML Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68029</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68029"/>
		<updated>2012-10-23T18:58:18Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML Diagram ==&lt;br /&gt;
[[File:UML.png]]&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68025</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68025"/>
		<updated>2012-10-23T18:19:30Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== UML Diagram ==&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68022</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68022"/>
		<updated>2012-10-23T18:15:31Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68021</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68021"/>
		<updated>2012-10-23T18:15:13Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display a different message depending on the type of operating system the code is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68020</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68020"/>
		<updated>2012-10-23T18:14:12Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
Now let's look at an implementation in Java. The code shows how we can implement a type of button, and clicking the button will display different messages depending on the type of operating system it is run on. The output should be either &amp;quot;I'm a WinButton&amp;quot; or &amp;quot;I'm an OSXButton&amp;quot; depending on which kind of factory was used. Note that the Application has no idea what kind of GUIFactory it is given or even what kind of Button that factory creates.&lt;br /&gt;
&lt;br /&gt;
    interface Buttonlike {&lt;br /&gt;
        public void paint();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    interface GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton();&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new WinButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXFactory implements GUIFactorylike {&lt;br /&gt;
        public Buttonlike createButton() {&lt;br /&gt;
            return new OSXButton();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class WinButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm a WinButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class OSXButton implements Buttonlike {&lt;br /&gt;
        public void paint() {&lt;br /&gt;
            System.out.println(&amp;quot;I'm an OSXButton&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    class Application {&lt;br /&gt;
        public Application(GUIFactorylike factory) {&lt;br /&gt;
            Buttonlike button = factory.createButton();&lt;br /&gt;
            button.paint();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
     &lt;br /&gt;
    public class ApplicationRunner {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
            new Application(createOsSpecificFactory());&lt;br /&gt;
        }&lt;br /&gt;
     &lt;br /&gt;
        public static GUIFactorylike createOsSpecificFactory() {&lt;br /&gt;
            int sys = readFromConfigFile(&amp;quot;OS_TYPE&amp;quot;);&lt;br /&gt;
            if (sys == 0) return new WinFactory();&lt;br /&gt;
            else return new OSXFactory();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68018</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68018"/>
		<updated>2012-10-23T18:05:03Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68017</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=68017"/>
		<updated>2012-10-23T18:04:47Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects. The Director need not know how the object is created. By just asking for the ''Computer'' configuration we need, the ''ComputerBuilder'' class generates the required object. &lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer. This is done in the ''Director'' class which specifies the configuration of ''Computer'' required.&lt;br /&gt;
&lt;br /&gt;
 class Director&lt;br /&gt;
  builder = ComputerBuilder.new&lt;br /&gt;
  builder.turbo&lt;br /&gt;
  builder.add_blu_ray(true)&lt;br /&gt;
  builder.add_hard_disk(100000)&lt;br /&gt;
  computer = builder.computer&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
==Class Diagram==&lt;br /&gt;
Lets look at the class diagram for the Builder Pattern:&lt;br /&gt;
&lt;br /&gt;
[[File:BuilderPattern.png]]&lt;br /&gt;
&lt;br /&gt;
The client of the ''ComputerBuilder'' i.e the code which instantiates the ''ComputerBuilder'' object is called the [http://sourcemaking.com/design_patterns/builder#permalink-5 Director]. The Builder class creates the complex objects and at the same time hides the implementation details from the Director.&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67658</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67658"/>
		<updated>2012-10-20T23:19:31Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class Tiger&lt;br /&gt;
      # Tiger specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Tree&lt;br /&gt;
      # Tree specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Frog&lt;br /&gt;
      # Frog specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Algae&lt;br /&gt;
      # Algae specific class implementation&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67657</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67657"/>
		<updated>2012-10-20T23:17:05Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67656</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67656"/>
		<updated>2012-10-20T23:13:34Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Let's say we are creating a Habitat which we populate with trees and animals. However, we need to ensure that the combination of trees and animals makes sense, viz. a client should add Algae and Frog together in the habitat, or Tiger and Tree, but not Tiger and Algae or Frog and Tree. We simply create two factories, one for adding Tigers and Trees and one for adding Frogs and Algae. The object dedicated to creating the compatible set of objects is the abstract factory.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    jungle.simulate_one_day&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
    pond.simulate_one_day&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67654</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67654"/>
		<updated>2012-10-20T23:06:26Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The output will be either &amp;quot;&amp;quot; or &amp;quot;&amp;quot; depending on what kind of Factory is used. As you can see, the client does not know what kind of Factory it is given.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
    &lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    jungle.simulate_one_day&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
    pond.simulate_one_day&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67653</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67653"/>
		<updated>2012-10-20T23:05:25Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The output will be either &amp;quot;&amp;quot; or &amp;quot;&amp;quot; depending on what kind of Factory is used. As you can see, the client does not know what kind of Factory it is given.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class JungleOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Tiger.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Tree.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Habitat&lt;br /&gt;
      def initialize(number_animals, number_plants, organism_factory)&lt;br /&gt;
        @organism_factory = organism_factory&lt;br /&gt;
&lt;br /&gt;
        @animals = []&lt;br /&gt;
        number_animals.times do |i|&lt;br /&gt;
          animal = @organism_factory.new_animal(&amp;quot;Animal#{i}&amp;quot;)&lt;br /&gt;
          @animals &amp;lt;&amp;lt; animal&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        @plants = []&lt;br /&gt;
        number_plants.times do |i|&lt;br /&gt;
          plant = @organism_factory.new_plant(&amp;quot;Plant#{i}&amp;quot;)&lt;br /&gt;
          @plants &amp;lt;&amp;lt; plant&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
We can now feed different abstract factories to our habitat, and also ensure that no illogical combinations of plants and animals exist in our created habitat.&lt;br /&gt;
&lt;br /&gt;
    jungle = Habitat.new(1, 4, JungleOrganismFactory.new)&lt;br /&gt;
    jungle.simulate_one_day&lt;br /&gt;
    pond = Habitat.new( 2, 4, PondOrganismFactory.new)&lt;br /&gt;
    pond.simulate_one_day&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. &lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
Lets define a ''Computer'' and other related objects in Ruby&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
===Java===&lt;br /&gt;
Not lets have a look at the same example in Java:&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67650</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67650"/>
		<updated>2012-10-20T22:58:04Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The output will be either &amp;quot;&amp;quot; or &amp;quot;&amp;quot; depending on what kind of Factory is used. As you can see, the client does not know what kind of Factory it is given.&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
    class PondOrganismFactory&lt;br /&gt;
      def new_animal(name)&lt;br /&gt;
        Frog.new(name)&lt;br /&gt;
      end&lt;br /&gt;
      def new_plant(name)&lt;br /&gt;
        Algae.new(name)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. Lets define a ''Computer'' and other related objects&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67649</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67649"/>
		<updated>2012-10-20T22:54:42Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The output will be either &amp;quot;&amp;quot; or &amp;quot;&amp;quot; depending on what kind of Factory is used. As you can see, the client does not know what kind of Factory it is given.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;(2012, October 17). Builder pattern. Retrieved from Wikipedia website: http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;(n.d.). Builder pattern. Retrieved from OODesign website: http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
Suppose we have to build a Computer which consists of several components like a hard disk, motherboard, disk drives and display.&lt;br /&gt;
Each of the components can be customized - hard disk can have some specified size, display could be Low-Def or Hi-Def, disk drives could be DVD or Blu-Ray. The motherboard itself has a CPU which could be Dual-Core or Quad-Core. It also has memory of some specified size. Lets define a ''Computer'' and other related objects&amp;lt;ref&amp;gt;Olsen, R. (2007). Easier object construction with the builder. In Design patterns in ruby (pp. 250-253). Addison Wesley. &amp;lt;/ref&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 class Computer&lt;br /&gt;
   attr_accessor :display&lt;br /&gt;
   attr_accessor :motherboard&lt;br /&gt;
   attr_reader   :drives&lt;br /&gt;
   def initialize(display=:low-def, motherboard=Motherboard.new, drives=[])&lt;br /&gt;
     @motherboard = motherboard&lt;br /&gt;
     @drives = drives&lt;br /&gt;
     @display = display&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class CPU&lt;br /&gt;
   # CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class DualCoreCPU &amp;lt; CPU&lt;br /&gt;
   # DualCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class QuadCoreCPU &amp;lt; CPU&lt;br /&gt;
   # QuadCore CPU details...&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Motherboard&lt;br /&gt;
  attr_accessor :cpu&lt;br /&gt;
  attr_accessor :memory_size&lt;br /&gt;
  def initialize(cpu=DualCoreCPU.new, memory_size=1000)&lt;br /&gt;
     @cpu = cpu&lt;br /&gt;
     @memory_size = memory_size&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 class Drive&lt;br /&gt;
  attr_reader :type # either :hard_disk, :blu_ray or :dvd&lt;br /&gt;
  attr_reader :size # in MB&lt;br /&gt;
  attr_reader :writable # true if this drive is writable&lt;br /&gt;
  def initialize(type, size, writable)&lt;br /&gt;
     @type = type&lt;br /&gt;
     @size = size&lt;br /&gt;
     @writable = writable&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
We can then define a ''ComputerBuilder'' class that lets one specify the configuration of each new Computer object you create and assembles them together.&lt;br /&gt;
&lt;br /&gt;
 class ComputerBuilder&lt;br /&gt;
  attr_reader :computer&lt;br /&gt;
  def initialize&lt;br /&gt;
    @computer = Computer.new&lt;br /&gt;
  end&lt;br /&gt;
  def turbo(has_turbo_cpu=true)&lt;br /&gt;
    @computer.motherboard.cpu = TurboCPU.new&lt;br /&gt;
  end&lt;br /&gt;
  def display=(display)&lt;br /&gt;
    @computer.display=display&lt;br /&gt;
  end&lt;br /&gt;
  def memory_size=(size_in_mb)&lt;br /&gt;
    @computer.motherboard.memory_size = size_in_mb&lt;br /&gt;
  end&lt;br /&gt;
  def add_blu_ray(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:blu_ray, 760, writer)&lt;br /&gt;
  end&lt;br /&gt;
  def add_dvd(writer=false)&lt;br /&gt;
    @computer.drives &amp;lt;&amp;lt; Drive.new(:dvd, 4000, writer)&lt;br /&gt;
  end&lt;br /&gt;
   def add_hard_disk(size_in_mb)&lt;br /&gt;
     @computer.drives &amp;lt;&amp;lt; Drive.new(:hard_disk, size_in_mb, true)&lt;br /&gt;
  end &lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Now the ''ComputerBuilder'' object can be used to specify the configuration needed on the Computer:&lt;br /&gt;
&lt;br /&gt;
 builder = ComputerBuilder.new&lt;br /&gt;
 builder.turbo&lt;br /&gt;
 builder.add_blu_ray(true)&lt;br /&gt;
 builder.add_hard_disk(100000)&lt;br /&gt;
 computer = builder.computer&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67645</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67645"/>
		<updated>2012-10-20T22:39:00Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67641</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67641"/>
		<updated>2012-10-20T22:32:01Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Abstract_factory_pattern#Usage&amp;lt;/ref&amp;gt;&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67640</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67640"/>
		<updated>2012-10-20T22:30:26Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means:&lt;br /&gt;
*The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations related to it. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.&lt;br /&gt;
*Adding new concrete types is done by modifying the client code to use a different factory, a modification that is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before – thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67639</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67639"/>
		<updated>2012-10-20T22:26:46Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client depends on some condition (and is not of the client's choosing) which is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67638</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67638"/>
		<updated>2012-10-20T22:20:39Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory] method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file and then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67637</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67637"/>
		<updated>2012-10-20T22:18:18Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the Abstract Factory method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file and then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67636</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67636"/>
		<updated>2012-10-20T22:17:56Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the Abstract Factory method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when a client needs to create an instance of a class from among a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file and then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67635</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67635"/>
		<updated>2012-10-20T22:16:43Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the Abstract Factory method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;.&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Abstract Factory Patterns are used when one needs to create an instance of a class from among a group of similarly related classes. The client does not know (or care) which type of class the client gets an instance of. The type of class returned to the client is usually stored in some sort of a configuration file. The abstract factory looks up this configuration file and then returns the corresponding class to the client.&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67632</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w18 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w18_as&amp;diff=67632"/>
		<updated>2012-10-20T22:08:48Z</updated>

		<summary type="html">&lt;p&gt;Avsarang: /* Abstract Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Abstract Factory and Builder Patterns=&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice&amp;quot;'' - [http://www.patternlanguage.com/leveltwo/ca.htm Christopher Alexander]&lt;br /&gt;
&lt;br /&gt;
''&amp;quot;In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design&amp;quot;.''&lt;br /&gt;
&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Design_Patterns Design Pattern] is a template to solve a problem which can be used in many different situations. It names, abstracts and identifies the key aspects of a common design structure that makes it useful for creating a reusable object - oriented design. Design Patterns in [http://en.wikipedia.org/wiki/Object-oriented_programming Object - Oriented Languages] help show the relationship between the different classes and objects in the program. Design Patterns are tools for building software.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Creational Patterns=&lt;br /&gt;
Creational Patterns are Design Patterns that somehow control the mechanism by which objects are created. They generally help to provide the following capabilities &amp;lt;ref&amp;gt;Stelting, S. (2002). Creational patterns. In Applied java patterns (p. 5). Palo Alto, California: Sun Microsystems. Retrieved from www.pearsonhighered.com/samplechapter/0130935387.pdf&amp;lt;/ref&amp;gt;:&lt;br /&gt;
* Generic instantiation – This allows objects to be created in a system without having to identify a specific class type in code.&lt;br /&gt;
* Simplicity – Some of the patterns make object creation easier, so callers will not have to write large, complex code to instantiate an object.&lt;br /&gt;
* Creation constraints – Some patterns enforce constraints on the type or number of objects that can be created within a system. The Singleton Pattern is an example of this type.&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory=&lt;br /&gt;
The basic purpose of the Abstract Factory method Pattern is to &amp;quot;Provide an interface for creating families of related or dependent objects without specifying their concrete classes&amp;quot;&amp;lt;ref&amp;gt;^ [|Gamma, Erich]; Richard Helm, Ralph Johnson, John M. Vlissides (2009-10-23). &amp;quot;Design Patterns: Abstract Factory&amp;quot; (in English) (HTML). informIT. Archived from the original on 2009-10-23. Retrieved 2012-05-16. &amp;quot;Object Creational: Abstract Factory: Intent: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.&amp;quot;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Builder=&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Builder_pattern Builder Pattern] is a design pattern that abstracts steps of construction of objects so that different implementations of these steps can construct different representations of objects&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Builder_pattern&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Complex applications require complex objects. Complex objects are usually made of sub-objects. These sub-objects generally have their own properties and configurations&amp;lt;ref&amp;gt;http://www.oodesign.com/builder-pattern.html&amp;lt;/ref&amp;gt;. For example consider a Car object. The Car object is made of many sub-objects like Steering Wheel, Wheels and Transmission. The Steering Wheel could be hydraulic driven or electronic. The Wheels could be tubeless or tubed. The Transmission could be automatic or manual. So to configure a Car object you will first have to configure the individual components and then put them together to build the Car.&lt;br /&gt;
&lt;br /&gt;
The Builder pattern allows you to build complex objects by specifying only its type and contents and not be worried about the implementation details. As a result different representations can be created using the same set of simple objects.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*--Java Example--&lt;br /&gt;
*--Ruby Example--&lt;br /&gt;
&lt;br /&gt;
=Comparison=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Avsarang</name></author>
	</entry>
</feed>