CSC/ECE 517 Fall 2009/wiki3 ksm 6: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:
The Gang of Four describes the Factories as [http://www.exforsys.com/tutorials/csharp/creational-design-patterns.html Creational patterns]. The Creational patterns are used in the creation of objects requiring to make decisions. They help us in encapsulating dynamic decisions regarding the instantiation of a class or the delegation of responsibilty  to objects. Sometimes we have to make a choice when we can use more than one creational pattern to a situation. While at times, we can combine multiple patterns simultaneously so that we can use them in our own advantage. Their general classification is:  
The Gang of Four describes the Factories as [http://www.exforsys.com/tutorials/csharp/creational-design-patterns.html Creational patterns]. The Creational patterns are used in the creation of objects requiring to make decisions. They help us in encapsulating dynamic decisions regarding the instantiation of a class or the delegation of responsibilty  to objects. Sometimes we have to make a choice when we can use more than one creational pattern to a situation. While at times, we can combine multiple patterns simultaneously so that we can use them in our own advantage. Their general classification is:  


*Abstract Factory Pattern - It is used in creation of different objects by objects without knowing the classes of objects being created. It is very helpful in working with different complex external entities like (different windowing systems) with similar functionality.  
*[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Pattern] - It is used in creation of different objects by objects without knowing the classes of objects being created. It is very helpful in working with different complex external entities like (different windowing systems) with similar functionality.  
For Example:
For Example:
We have to create a user interface framework that can be used to work on top of multiple operating systems. This is done using an abstract class for each type of [http://en.wikipedia.org/wiki/Widget widget] and then write a concrete subclass for each class (for each supported platform).   
We have to create a user interface framework that can be used to work on top of multiple operating systems. This is done using an abstract class for each type of [http://en.wikipedia.org/wiki/Widget widget] and then write a concrete subclass for each class (for each supported platform).   




*The Builder Pattern - It is used in determining the class of an object .
*[http://en.wikipedia.org/wiki/Builder_pattern The Builder Pattern] - It is used in determining the class of an object .


*The Factory Method Pattern - It is a way by which an object can start the creation of other objects without knowing about their classes.
*[http://sourcemaking.com/design_patterns/factory_method The Factory Method Pattern] - It is a way by which an object can start the creation of other objects without knowing about their classes.


*The Prototype Pattern - This Pattern is used in creation of customized objects by an object without knowing their class or the details about their creation.
*[http://en.wikipedia.org/wiki/Prototype_pattern The Prototype Pattern] - This Pattern is used in creation of customized objects by an object without knowing their class or the details about their creation.


*The Singleton Pattern - It is used in sharing of a common object by multiple objects without even knowing if it already exists.
*[http://www.c-sharpcorner.com/UploadFile/susanabraham/CreationalPatterns06042005050058AM/CreationalPatterns.aspx The Singleton Pattern] - It is used in sharing of a common object by multiple objects without even knowing if it already exists.


These general classifications are based on three broad classifications:
These general classifications are based on three broad classifications:


*Behavioral Pattern - used to contain variation of behavior.
*[http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral Pattern] - used to contain variation of behavior.


*Structural Pattern - used to integrate an existing code into new object-oriented design.
*[http://www.exforsys.com/tutorials/csharp/structural-and-behavioral-design-patterns.html Structural Pattern] - used to integrate an existing code into new object-oriented design.


*Factory Pattern - used in the creation of objects.
*[http://en.wikipedia.org/wiki/Factory_method_pattern Factory Pattern] - used in the creation of objects.




='''Problem'''=


Let us consider the problem of creating a framework for desktop applications.It will have the following requirements-
*Support provided for operations such as creation, opening, saving etc.
*A consistent set of methods that can be called when the command is given.
*A document interface that is application independent.
*Concrete classes that implement the interface.
*An abstract class providing logic that is application independent.
='''Solution'''=
*A class providing the methods. Let us call it ''Application class''.
*Providing a class that can be used to encapsulate the required logic in the selection as well as instantiation of classes that are application specific.
*An interface could be provided that can be implemented by the class provided by the programmer. So that the Application class can call the class provided by the programmer without being dependent on it.
*The interface declares a method that can be implemented by the class provided by the programmer in selecting as well as instantiating a class.
*The Application class works through the interface provided by the framework rather than class provided by the programmer.


='''Uses'''=
='''Uses'''=
Line 42: Line 66:
='''Links'''=
='''Links'''=


[[http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki3_ Factory method design pattern wikipedia]]
*[http://gsraj.tripod.com/design/creational/factory/factory.html Factory Pattern]
 
*[http://gsraj.tripod.com/design/creational/factory/factory.html Advantages of Factory method]


[[http://gsraj.tripod.com/design/creational/factory/factory.html Advantages of Factory method]]
*[http://gsraj.tripod.com/design/creational/factory/factory.html]


[[ http://gsraj.tripod.com/design/creational/factory/factory.html]]
*[http://today.java.net/article/2009/10/28/applying-creational-design-patterns-java Creational Patterns in Java]


='''Referances'''=
='''Referances'''=

Revision as of 07:12, 18 November 2009

The Factory Design Pattern And Its Application

Introduction

A programmer, at the time of designing, usually is concerned about their behavior. But other aspects such as the availability of a particular object at the time when it is required also need to be considered. The rules of creation should be followed. Sometimes, the developers intermix the management of object creation with object instantiation. Using same code for object creation as well as object instantiation, can lead to complexity of code. It has to keep a track of object creation, construction parameters, as well as the use of those objects after creation. This leads to several consequences such as reducing coupling as well as selection of an instantiation scheme early. To address these issues, Factories are used which help to keep the objects cohesive, testable and decoupled. The design becomes flexible and the problem can be split into chunks of manageable pieces.

Overview

In this article,we are going to discuss about Factory method Pattern. We will first look at the objectives of Creational patterns. Then we will have a look at different Creational patterns. We will try to find out how and why the Factory Method Pattern has an edge over other Creational patterns. How Factory method design pattern is implemented in some Object Oriented languages. Finally we will discuss about the uses as well as the contribution of Factory pattern in providing an elegant solution to a problem.

Features

The Gang of Four describes the Factories as Creational patterns. The Creational patterns are used in the creation of objects requiring to make decisions. They help us in encapsulating dynamic decisions regarding the instantiation of a class or the delegation of responsibilty to objects. Sometimes we have to make a choice when we can use more than one creational pattern to a situation. While at times, we can combine multiple patterns simultaneously so that we can use them in our own advantage. Their general classification is:

  • Abstract Factory Pattern - It is used in creation of different objects by objects without knowing the classes of objects being created. It is very helpful in working with different complex external entities like (different windowing systems) with similar functionality.

For Example: We have to create a user interface framework that can be used to work on top of multiple operating systems. This is done using an abstract class for each type of widget and then write a concrete subclass for each class (for each supported platform).


  • The Factory Method Pattern - It is a way by which an object can start the creation of other objects without knowing about their classes.
  • The Prototype Pattern - This Pattern is used in creation of customized objects by an object without knowing their class or the details about their creation.
  • The Singleton Pattern - It is used in sharing of a common object by multiple objects without even knowing if it already exists.

These general classifications are based on three broad classifications:


Problem

Let us consider the problem of creating a framework for desktop applications.It will have the following requirements-

  • Support provided for operations such as creation, opening, saving etc.
  • A consistent set of methods that can be called when the command is given.
  • A document interface that is application independent.
  • Concrete classes that implement the interface.
  • An abstract class providing logic that is application independent.

Solution

  • A class providing the methods. Let us call it Application class.
  • Providing a class that can be used to encapsulate the required logic in the selection as well as instantiation of classes that are application specific.
  • An interface could be provided that can be implemented by the class provided by the programmer. So that the Application class can call the class provided by the programmer without being dependent on it.
  • The interface declares a method that can be implemented by the class provided by the programmer in selecting as well as instantiating a class.
  • The Application class works through the interface provided by the framework rather than class provided by the programmer.

Uses

Links

Referances

  • Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition ,By: Alan Shalloway; James R. Trott.

ISBN-978-0-321-24714-8

  • Design Patterns In Java