I have a class that stores some temporary data. This class has “deleteOld” method for clearing expired data.
Is it a good idea to pass parameter to that function to set expiration period? I mean something like deleteOld(expiredDays).
Or this function should encapsulate expiredDays parameter?
deleteOld()
{
// get expiredDays from config
}
‘expiredDays’ is constant that set in config.
First variant looks more flexible. But second one looks more OOP, beacuse class clients doesn’t need to know anything about expiredDays. Second way doesn’t reveal details of class realization.
It is PHP, but I guess it is doesn’t matter
What do you think? Thanks.
It always depends, mostly on business logic. If a value controls some aspect of the business logic, it can be given as a parameter. That is what parameters are for.
In your case I think that
expiredDaysis a business matter for managing the stored data, so revealing this is no problem. Except your business logic requires that nobody from outside shall change it. As I said, it depends.What you won’t to be revealed is probably the way, how the data gets stored (filesystem, DB, …).