I case that four types of data objects: and four different TreeNode type of GUI framework, specific to each one wrapped data type: Now I have frequent patterns that I have an example of a datatype and should be a new instance of MyAppTreeNode. I give you two find solutions A: Solution two: The solution uses a polymorphism, less is more "elegant" but I would have no idea about the GUI Framework datatype classes that I use. Maybe I can also use two separate GUI frameworks? Do you see a third solution? I added the Gis tag for this question. Perhaps there are some functions in Geice or any other dependency injection library which can help here? By looking at similar questions: The visitor is induced approach for this as always in a datatype object in one Then there will be something like this in the code data model and in GUI you have class DataTypeAlpha the data type class DataTypeBeta extends data type class DataTypeGamma extends data type class DataTypeDelta extends data type
class Alfred note expands MyAppTreeNode ...
class datatype {// Instantiates and appropriate MyAppTreeNode for the DataType essence MyAppTreeNode createTreeNode (); }
class MyAppTreeNode {static MyAppTreeNode createTreeNodeForDataType (datatype) {if (datatype Instanceof DataTypeAlpha) New AlphaTreeNode return ((DataTypeAlpha) datatype) else if (datatype Instanceof DataTypeBety) return new BetaTreeNode ((DataTypeBeta) datatype) and that ... (and if throwing someone else ... new IllegalArgumentException); }} What does
Acceptable method, but unlike normal visitor patterns, it does not exceed children and will return a value. To avoid too much confusion, call the near object call to
accept for
the visitor rather than the
operator . The
accept and
operator are a normal way to return.
public intangible class datatype {public abstract & lt; T & gt; Acceptance of T (operator & lt; T & gt; op); } Public Interface operator & lt; T & gt; {T-opera alpha (datatype alfa data); T Operate Beta (Datatype Beta Data); ...} Public category dataType alpha datatype {public & lt; T & gt; T accept (operator op) {return op.operateAlpha (this); }} ....
public square tree node factor equipment operator & lt; MyAppTreeNode & gt; {Public MyAppTreeNode powered alpha (datatype alfa data) {Returns new alpha-print (data); } ...} Public class MyAppTreeNode {Static Tree Node Factory Factory = ...; Static MyAppTreeNode createTreeNodeForDataType (DataType Datatype) {return dataType.accept (factory); }}
No comments:
Post a Comment