Factory Patterns:Factory Method and Abstract Factory
#1

Factory Patterns:Factory Method and Abstract Factory
Factory Patterns
l Factory patterns are examples of creational patterns
l Creational patterns abstract the object instantiation process.
They hide how objects are created and help make the overall
system independent of how its objects are created and composed.
l Class creational patterns focus on the use of inheritance to decide
the object to be instantiated
é Factory Method
l Object creational patterns focus on the delegation of the
instantiation to another object
é Abstract Factory
Factory Patterns
l All OO languages have an idiom for object creation. In Java this
idiom is the new operator. Creational patterns allow us to write
methods that create new objects without explicitly using the new
operator. This allows us to write methods that can instantiate
different objects and that can be extended to instantiate other
newly-developed objects, all without modifying the method's
code! (Quick! Name the principle involved here!)
The Factory Method Pattern
l Intent
é Define an interface for creating an object, but let subclasses decide which
class to instantiate. Factory Method lets a class defer instantiation to
subclasses.
l Motivation
é Consider the following framework:
é The createDocument() method is a factory method.
The Factory Method Pattern
l Applicability
Use the Factory Method pattern in any of the following situations:
é A class can't anticipate the class of objects it must create
é A class wants its subclasses to specify the objects it creates
l Structure
The Factory Method Pattern
l Participants
é Product
Ý Defines the interface for the type of objects the factory method creates
é ConcreteProduct
Ý Implements the Product interface
é Creator
Ý Declares the factory method, which returns an object of type Product
é ConcreteCreator
Ý Overrides the factory method to return an instance of a ConcreteProduct
l Collaborations
é Creator relies on its subclasses to implement the factory method so that it
returns an instance of the appropriate ConcreteProduct
The Factory Method Pattern
l So what exactly does it mean when we say that "the Factory
Method Pattern lets subclasses decide which class to instantiate?"
é It means that Creator class is written without knowing what actual
ConcreteProduct class will be instantiated. The ConcreteProduct class
which is instantiated is determined solely by which ConcreteCreator
subclass is instantiated and used by the application.
é It does not mean that somehow the subclass decides at runtime which
ConreteProduct class to create
Factory Method Example 1 (Continued)
l Note that although the Client delegates the creation of a
ConcreteManipulator to a ConcreteFigure object, the focus of the
pattern is still on how a specific subclass of Figure creates one
particular type of Manipulator. So this is still the Factory Method
Pattern (a class creational pattern).
Factory Method Example 2 (Continued)
l Here's a MazeGame class with a createMaze() method:
/**
* MazeGame.
*/
public class MazeGame {
// Create the maze.
public Maze createMaze() {
Maze maze = new Maze();
Room r1 = new Room(1);
Room r2 = new Room(2);
Door door = new Door(r1, r2);
maze.addRoom(r1);
maze.addRoom(r2);
Design Patterns In Java Bob Tarr Factory Patterns
12
Factory Method Example 2 (Continued)
r1.setSide(MazeGame.North, new Wall());
r1.setSide(MazeGame.East, door);
r1.setSide(MazeGame.South, new Wall());
r1.setSide(MazeGame.West, new Wall());
r2.setSide(MazeGame.North, new Wall());
r2.setSide(MazeGame.East, new Wall());
r2.setSide(MazeGame.South, new Wall());
r2.setSide(MazeGame.West, door);
return maze;
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: filetype pdf on factory visiting report, ice cream factory project report download, abstract factory abap, project on factory act 1948, questionnaire of techniques of scientific management regarding parle g factory, major factory industrial accidents in haridwar, sugar factory training report pdf,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  NOKIA MORPH TECHNOLOGY abstract seminar details 3 5,835 08-04-2014, 10:35 PM
Last Post: seminar report asees
  Audio Steganography Using Bit Modification Abstract seminar details 1 1,871 10-11-2012, 11:58 AM
Last Post: seminar details
  SF6 Circuit Breaker Abstract project uploader 1 2,791 31-10-2012, 01:47 PM
Last Post: seminar details
  Types and Functions of Jigs and Fixtures project uploader 1 3,221 27-10-2012, 04:11 PM
Last Post: seminar details
  Obstacles Avoidance Method for an Autonomous Mobile Robot using Two IR Sensors project uploader 0 1,034 11-06-2012, 01:18 PM
Last Post: project uploader
  VIRTUAL DATABASE TECHNOLOGY FOR DISTRIBUTED DATABASE abstract seminar details 0 1,397 09-06-2012, 06:00 PM
Last Post: seminar details
  PROTOTYPING AND DYNAMIC ANALYSIS OF ROTOR SHAFT AND HUB seminar details 0 416 08-06-2012, 05:13 PM
Last Post: seminar details
  AUTOMATIC RAILWAY GATE CONTROL abstract seminar details 0 965 08-06-2012, 04:57 PM
Last Post: seminar details
  NC and CNC machines and Control Programming ppt seminar details 0 2,105 08-06-2012, 12:53 PM
Last Post: seminar details
  5G Based on Cognitive Radio abstract seminar details 0 698 08-06-2012, 12:43 PM
Last Post: seminar details

Forum Jump: