Is builder design pattern is the right one to create itemBrowsePanel
object? this object needs 2 others objects (iconBrowsePanel,textBrowsePanel)
in order to be ready to use, as follows:
HTMLPanel itemBrowsePanel=new HTMLPanel("");
HTMLPanel iconBrowsePanel=new HTMLPanel("");
HTMLPanel textBrowsePanel=new HTMLPanel("");
HTMLPanel titlePanel=new HTMLPanel(titlePanelText);
HTMLPanel subTitlePanel=new HTMLPanel(subTitlePanelText+" "+panelName);
textBrowsePanel.add(titlePanel);
textBrowsePanel.add(subTitlePanel);
itemBrowsePanel.add(iconBrowsePanel);
itemBrowsePanel.add(textBrowsePanel);
if builder design pattern is the right one, is it applicable to pass arguments to any object on creation in order to construct other objects ?
iconBrowsePanel
andtextBrowsePanel
are added toitemBrowsePanel
before it is used, then it is better to create anItemBrowsePanel
class with a specific constructor which takes these parameters and ensures the invariantIf you want to reuse the existing construction algorithm elsewhere, it is better to wrap in into a method which takes parameters like
titlePanelText
,subTitlePanelText
orpanelName
and returns a fully constructedHTMLPanel
, which represents anitemBrowsePanel
If there are too many parameters and / or parameter combinations to create
itemBrowsePanel
, then yes, it may be appropriate to use a builder