The Situtation is that there is a data named Progress
which has 2 valid values (suppose 'A'
and B
). this means Progress = 'A'
or Progress = B
. A
is just a string
, but B
is not string
. B
itself has some valid values (suppose strings: 'V1'
, 'V2'
, 'V3'
). progress
can be A
which is a string
or can be B
which is 'V1'
, 'V2'
or 'V3'
. How to model this data?image
If B
is just a simple string (just like A
) so we can define Progress
as a string
but i think one solution is defining progress
as a class which has two children: Class A
& Class B
. Class B
has 2 fields: Id & state
so we have 3 IDs which correspond to 3 states
: 'V1'
, 'V2'
and 'V3'
and Class A
with a const
field called state
with fixed value 'A'
. so with this solution progress
can be objects A
or B
which has a state
.
Please help me if such design is not good or if there is any design pattern for such situation.
Aucun commentaire:
Enregistrer un commentaire