Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-2288

Builder pattern for simple objects

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Non-Essential
    • Resolution: Won't Fix
    • None
    • None
    • None
    • Medium

    Description

      I do not like how SimpleObject is created with the every other element pattern. In my opinion a better approach is to use the builder pattern as in http://stackoverflow.com/questions/328496/when-would-you-use-the-builder-pattern/1953567#1953567 and have something like
      SimpleObject.Builder().put("patientId", patient.getId()).put("activeIdentifiers", patient.getActiveIdentifiers()).build();
      or
      SimpleObject.Builder(patient).build();

      Furthermore, SimpleObject.Builder will be calling ui.simplifyObject on every object in case there is a converter and as a result in a controller we will have
      return new ObjectResult(SimpleObject.Builder(patient).build());
      or
      return new ObjectResult(SimpleObject.Builder().put("patientId", patient.getId()).put("activeIdentifiers", patient.getActiveIdentifiers()).build());
      or even
      return new ObjectResult(SimpleObject.Builder(patient).put("locations", patient.getLocations()).build());

      Gliffy Diagrams

        Attachments

          Activity

            People

              Unassigned Unassigned
              raff Rafal Korytkowski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: