java - When using the builder pattern, is there a way to pass data from one of the objects being used to build to another object? -


i have 2 objects put create object in builder pattern in java. 1 payloaddata abstract class object, other headerdata object (not abstract). inherit interface called messageelement. however, need payloaddata object pass size (i have code creates variable in payload has stored) header object. how can this? payloaddata abstract object overriden "type"payload (the type of data stored payload).

headerdata has method calculating overall message size:

    public int messagesize() //this method finsihed already, needs fixed.     {          return payloaddata.elementsize() + 16; //something here need fixed.     } 

but doesn't seem work.

payloaddata has method (which overridden class inherits it:

public int elementsize() {     // todo auto-generated method stub     return 0; } 

the concrete object has this: override it:

    @override public  int elementsize() //this 1 override think needed.  need figure out how pass //headerdata, right not accepting it. {     return (48 + 184 * tracksinmessage());  } 

i think need modify builder pattern i'm using let headerdata access elementsize, how should that?

remember there class built, message class in case, assembled headerdata class , class inherits payloaddata, , there builder class , class uses builder class create message objects.

here pattern followed way, replaced burger payloaddata , replaced colddrink headerdata made concrete object:

http://www.tutorialspoint.com/design_pattern/builder_pattern.htm


Comments