What I want:
- An object that behaves like a
float
, I mean that support the most operations afloat
supports so it can be used in any expression afloat
can be used too. - The object MUST NOT had a value until it's needed.
Some kind of lazy float
.
Motivation:
The object represents a value in a Data Base and the real value of the object is in the DB (getting its value could be expensive), also when the object is assigned or under certain operations it must update the value in the DB (like the operation increment by a value, which should be modelled as a method of the object). Remark: if we just want to increment the value, we don't need and don't want to get the real value from the DB.
The question: It is possible to subclass float
and overwrite some (or just one) of its methods to achieve the proposed objectives?
Note: please, I know the solution to the problem maybe (almost for sure) is not the best, but I posted it just as an example, It came to my mind trying to answer this question if you want to offer a better solution to the problem post it in the original question, thanks.