I was creating a class model using inheritance, and have a situation I don't know how to represent.
For this question I built an example diagram in which I have a class Person
with some attributes.
I also have a class Class1
that needs to use objects of a new class with Person
's attributes plus sex
and birthDate
attributes, so I create a Person2
class which inherits from Person
.
But I also have another class Class2
which needs to use objects with only the Person
attributes, not Person2
. I can't use an association relationship because Person
is an abstract class.
How should I handle this situation?
person: Person
attribute has that type), but you can assign a Person2 instance to the variable (that's what inheritance allows you to do - substitute a derived type where an object of the base class is expected). P.S. your inheritance arrow should go from Person2 to Person.