3

I have a dwelling class which is a generalization of house and building. Those classes have their own properties, and the class floor is a composite of building.

UML Class Diagram

I would like to associate a person class. If a person lives in a building, I want to be able to retrieve the matching floor. The best solution I found is to import all properties in the parent class and make them nullable.

Q: Is there a more elegant way to deal with such scenario ?

EDIT: I forgot to say (and to draw) that dwelling is an abstract class, as a :dwelling is either a :building or a :house. As I cannot predict in which a :person will be, the relationship should only involve the dwelling class. But how instantiate once I know ?

Hicham
  • 31
  • 4
  • 2
    Are you looking for advice modeling objects, or how to represent this object schema in a relational database? Your question seems to be more directed at object modeling, and as such isn't a great fit for this site. – Erik Aug 27 '15 at 22:56
  • I'm looking for the best way to model a relationship between a class and inherited classes, so it's seems to be an object modeling problem. Sould I rather post on Stack Overflow ? Thanks. – Hicham Aug 27 '15 at 23:26

1 Answers1

0

Maybe something like this:

enter image description here

  • Person's home is a LivingPlace
  • Concrete LivingPlace's are House and Apartment
  • Concrete Dweling's are House and Building
  • A Building has Floor's, a Floor knows its Building
  • A Floor has Apartment's, a Apartment knows its Floor
sergej
  • 17,147
  • 6
  • 52
  • 89