Define abstract classes for the city object types #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I propose this way for the definition of city object types. The idea is that we can introduce abstract types (denoted as
_AbstractType
) which define the basic properties of the objects and, then, there is a simple concrete type that include those properties and only adds thetype
property (e.g., see_AbstractBuilding
andBuilding
in 7b94613).There are certain benefits:
_AbstractCityObject
, which all city objects extend. In addition, for complex types such asBuildingParts
we can reuse parts from existing objects (e.g., see ab53416).Building
without specifying a new type they can simply extend theBuilding
object. If they want to make a new building type, though, they can extend the_AbstractBuilding
and just add their owntype
property. In any case, they don't have to rewrite all properties of the original class.As a caveat, though, we can't use the
additionalProperties: false
option with this mechanism (see why here), therefore we cannot force objects to only have the properties of the schema. There is a workaround, by listing again all "inherited" properties in the last class (explained at the end of this answer). Nevertheless, I believe it's better to just warn users about this through cjio validation, than really forcing them to follow the schema. After all, the whole point of JSON is to be more flexible.