1 Replies - 4820 Views - Last Post: 31 October 2010 - 10:45 AM Rate Topic: -----

#1 Chette   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 31-October 10

Using the Composite pattern with the factory design pattern

Posted 31 October 2010 - 07:23 AM

I'm quite new to the concept of design patterns, but I was wondering how one would go about implementing the composite pattern with the factory method pattern. For example, the code in the example in wikipedia - http://en.wikipedia....te_pattern#Java How would one then implement the factory method pattern to instantiate, say, a new ellipse or a new square...etc. Thanks in advance for any answers.

Is This A Good Question/Topic? 0
  • +

Replies To: Using the Composite pattern with the factory design pattern

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: Using the Composite pattern with the factory design pattern

Posted 31 October 2010 - 10:45 AM

The factory would something like this:

public class ShapeFactory{
     public static Square getSquareInstance() {
          return new Square(); //could add prams, etc...
     }
     //etc... for other shapes
}



You could then use the factory to fill your composite object.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1