There is an object which is very complicated to build and many algorithms needed to figure out how it should be created (for your curiosity it is an object that represents and draws the beaming of notes in music notation).

The object has a rats nest of internal logic which I want to, at least partially, externalize in some sort of builder object.

However I found that the builder object needed too much access to the internals of the object it is constructing. So I came up with a different approach. The 'builder' object will instead be a representation of the complex real-world thing that the 'constructed' object will represent, but the 'constructed' object will still build itself taking the 'builder' object as input to the constructor.

I don't think this is exactly a GOF Builder Pattern. Is there a design pattern which more closely matches my proposal? I would like to search on it if there is.

In case the above description isn't clear, here is snippet that shows what I mean.

class ComplexBuildingInstructionsIntf
    virtual ~ComplexBuildingInstructionsIntf() {}
    virtual int getLots() const = 0;
    virtual int getComplicated() const = 0;
    virtual int getStuff() const = 0;

class ComplexObject
    ComplexObject(const ComplexBuildingInstructionsIntf& inInstructions);
  • 1
    This is called "Joshua Bloch's Builder pattern", see rwhansen.blogspot.de/2007/07/… – Doc Brown Nov 15 '16 at 17:02
  • 1
    @DocBrown Actually no. What the op calls a 'builder object' is the parameter object pattern. – candied_orange Nov 15 '16 at 17:28
  • 1
    @CandiedOrange: ok, "Joshua Bloch's Builder pattern" is surely not an official pattern name, but the core idea described in that article is the same. – Doc Brown Nov 15 '16 at 19:51
  • 2
    @DocBrown "Joshua Bloch's Builder Pattern is official enough for me. Call it the Builder Pattern in Effective Java if you like. That builder might solve the problem the OP presented. But the OP wasn't asking for just any solution that would work. He was asking: "Is there a design pattern which more closely matches my proposal?" His proposal is a self building parameter object. – candied_orange Nov 16 '16 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.