Hyperlink improvements [experimental]
Description
In TG there is a concept of "hyperlinks", which are strings that represent valid URLs. Hyperlinks are modelled with type Hyperlink, which has a single public constructor Hyperlink(value: String), which performs validation of value, preventing instantiation of invalid hyperlinks. The same type Hyperlink is used when retrieving data from a database. This has a disadvantage where retrieving persisted, and thus already validated, hyperlink values goes through a validation process again. For hyperlinks such validation is not a major performance concern per se, but in some other cases, it might be.
Generally speaking, data retrieval from a database should not perform data validation. However, allowing instantiation of Hyperlink without validation requires tight control over who and when should be able to do that. It may also be desirable to easily distinguish between values that were validated during instantiation and those that are considered valid, but were not validated (e.g., values retrieved from a database).
In strongly typed programming languages, such as Haskell, there is an idea of representing persisted and transient values of the same concept as different, although polymorphic, types (sorry, no reference as I cannot remember where I read that (: ). Following this idea and using the capabilities of Modern Java, we can implement a private constructor for Hyperlink, which does not perform any validation, and redefine Hyperlink as a sealed class with only one permits type Hyperlink.Persited that would have access to the new private constructor. And so, only Hyperlink.Persisted would be able to instantiate Hyperlink without validation. However, we would also like to further limit Hyperlink.Persisted instantiation to the code that is responsible for the data retrieval. In our case, we need to limit such instantiation to HyperlinkType. This can be achieved by placing Hyperlink and HyperlinkType into the same package, albeit 2 different modules, and making Hyperlink.Persisted package-private.
Expected outcome
Improved performance when retrieving Hyperlink values from a database. Easy identification of persisted hyperlink values.