I'm converting some old procedural code to OOP.
Lets say I have some procedural code that marks a record as trashed and records the time that is done.
UPDATE
toys
SET
is_trashed = 1,
trashed_date_timestamp = NOW()
WHERE
id = ??
I gather, from the various books on OOP, that in the object oriented paradigm you:
- 'find' a specific item as an object, and then
- modify its properties, and then
- save its properties to the db using a generic 'update' method on an ORM mapper
This is in contrast to the procedural/db-centric method used in my code where I run an SQL query to update a specific record with specific values in the db for a specific change of properties.
So, lets say I wanted to convert this code to the Object Oriented paradigm.
- I find my object by its id, and
- modify its properties:
- I set the isTrashed property to TRUE
- I set the trashedDateTimestamp property to ???
huh!?
When I try to set the trashedDateTimestamp property to NOW its opens up a whole load of issues.
- What is now? I'd prefer to ensure that it is the NOW() from the database time, not NOW on the server.
- How do clients of the toy object handle getting and setting that trashedDateTimestamp property?
I can think of lots of ways to 'skin this cat' but would like to know if there are any patterns that solve this issue.
Or is this feature proven to be impossible in the OO Paradigm and I should use something like an 'events observer' instead.
In short - How do you store NOW onto object properties with reasonable accuracy?