BVal
  1. BVal
  2. BVAL-73

Alternative way of addressing code reuse issue between the validators

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.2-incubating
    • Fix Version/s: 0.2-incubating
    • Component/s: None
    • Labels:
      None

      Description

      Currently, the code reuse issue exposed in BVAL-47 has been solved using a common abstract validator which is subclassed by the jsr303 and core validators.

      I have been thinking about how to solve the type safety problems I exposed in my mail. I propose a different solution (no inheritance, and a strategy pattern is used to return the validation flow to the correct method in each validator in a type safe way). The reasons why I propose removing the current inheritance scheme are:

      • Inheritance is just used for code reuse. The 2 validatos have different interfaces to which they respond to, and there is no code in which a reference to an "abstract" validator is or should be held.
      • I haven't found a way of removing class casting issues with the inheritance strategy. I know that at the moment it is somewhat "easy" to see that most of the casts can't fail, but I find it cleaner and safer to code it in a way in which type safety is enforced by the compiler.

      Please take into account that the proposed diff is a preliminar work that simply shows a way in which this could be done. If you prefer this to the current solution with inheritance, further work would be done to better ensure type safety, access to the property treatsMapsLikeBeans would be centralized, etc.

        Activity

        Hide
        Carlos Vara added a comment -

        As there is no opposition, I merged a slightly modified version of the patch in rev 962902.

        Show
        Carlos Vara added a comment - As there is no opposition, I merged a slightly modified version of the patch in rev 962902.

          People

          • Assignee:
            Carlos Vara
            Reporter:
            Carlos Vara
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development