Click
  1. Click
  2. CLK-565

Provide Control builder / factory class

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.3.0
    • Component/s: examples
    • Labels:
      None

      Description

      Using a factory or builder pattern to create controls is a great way to reduce the number of lines of code in an application and can also help standardize your application.

      There are 2 common pattners for doing this, one is the factory pattern, for example:

      Table sizesTable = new Table("sizes");
      ControlFactory.addColumn(table, "label", "Metric");
      ControlFactory.addColumn(table, "value");

      The other is the builder pattern, for example:

      Table sizesTable = TableBuilder.simpleBuilder("sizes").addColumn("label", "Metric").addColumn("value").build();

      Both of these styles have pros and cons. Please see attached examples.

      1. ControlFactory.java
        10 kB
        Malcolm Edgar
      2. TableBuilder.java
        5 kB
        Malcolm Edgar

        Activity

        Malcolm Edgar created issue -
        Malcolm Edgar made changes -
        Field Original Value New Value
        Attachment ControlFactory.java [ 12412437 ]
        Attachment TableBuilder.java [ 12412438 ]
        Malcolm Edgar made changes -
        Component/s extras [ 12312710 ]
        Hide
        Adrian A. added a comment -

        TableBuilder looks nice because it allows a sort of "chaining", without changing the Table API.
        I saw similar patterns, but the naming was a little different:
        TableBuilder.simpleTable("sizes")....
        So TableBuilder.xxxTable() instead of TableBuilder.xxxBuilder()....

        ControlFactory on the other hand doesn't look to save much code.

        Show
        Adrian A. added a comment - TableBuilder looks nice because it allows a sort of "chaining", without changing the Table API. I saw similar patterns, but the naming was a little different: TableBuilder.simpleTable("sizes").... So TableBuilder.xxxTable() instead of TableBuilder.xxxBuilder().... ControlFactory on the other hand doesn't look to save much code.
        Adrian A. made changes -
        Assignee Adrian A. [ a_adrian ]
        Adrian A. made changes -
        Fix Version/s 2.3.0 [ 12314845 ]
        Adrian A. made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Adrian A. made changes -
        Fix Version/s 2.4.0 [ 12315123 ]
        Fix Version/s 2.3.0-M1 [ 12314845 ]
        Hide
        Bob Schellink added a comment -

        I'm placing this under examples.

        I don't think adding App specific patterns to Click is the way to go. The same effect can be achieved as an example without adding more abstraction and surface area to the framework.

        Show
        Bob Schellink added a comment - I'm placing this under examples. I don't think adding App specific patterns to Click is the way to go. The same effect can be achieved as an example without adding more abstraction and surface area to the framework.
        Bob Schellink made changes -
        Priority Major [ 3 ] Minor [ 4 ]
        Component/s examples [ 12312708 ]
        Component/s extras [ 12312710 ]
        Adrian A. made changes -
        Status In Progress [ 3 ] Open [ 1 ]
        Hide
        Adrian A. added a comment -

        The project Chainer:
        http://code.google.com/p/chainer/
        solves this problem nicely and it's already listed on the Click main site.

        Show
        Adrian A. added a comment - The project Chainer: http://code.google.com/p/chainer/ solves this problem nicely and it's already listed on the Click main site.
        Adrian A. made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.0 [ 12316244 ]
        Fix Version/s 2.4.0 [ 12315123 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Adrian A.
            Reporter:
            Malcolm Edgar
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development