mercredi 13 janvier 2016

Model an overview object in an object oriented way

I have an api that displays, let's say, cities:

/cities
/city/{id}

The cities endpoint returns an overview of the city (id, city name, city area), whereas the city endpoint returns the same plus some more (population, image, thumbnail...). Now, when modelling this in the client I see different alternatives:

  1. Have a CityOverview class which has a City subclass that adds the extra attributes.
  2. Have a City class that has all the attributes with a CityOverview subclass that hides all the extra attributes (say, in Java, by throwing an UnsupportedOperationException on all the getters for attributes it doesn't have).
  3. Have the above classes with no inheritance relationship.
  4. Have a single City class that allows all the extra attributes to be nulled.

What are the pros and cons of the above approaces and/or any other you can think of?

Aucun commentaire:

Enregistrer un commentaire