Closed mdbs99 closed 7 years ago
About ifs, there is nothing wrong with ifs in OO world, as long as such if is not spread over the place and causing maintenance problems. Most of the time we should replace ifs with polymorphic calls, but there are some cases in which ifs are just fine, because the "if i didn't cache this value, then get it, else return cached value" is just fine. Every "purist OO solution" will end up in more complicated code, and simple is just better than any complicated stuff. As long as the "if i didint cache this thing" isn't spread all over the place, I say, such if statement is fine, hidden in the implementation of a decorator that consumers will not ever notice and care about
There are no problems with ifs when they are used in conditionals within the behavior of an object to make decisions about the state of that same object. When we have a code that are supposing something about other objects, then we have a "controller". This is not good because, in object-oriented design, we should not have a controller telling the objects what to do and in what sequence to do. We should have only objects working together.
I've just realized that we don't need such class. To make this happen using the "Tell Do not Ask" principle is by using anonymous functions. But, IMHO, this is not a real OOP. The code for those functions will exists so, why not create them inside a class, as methods?
Besides that, we always can create decorators — as @ortuagustin said https://github.com/mdbs99/james/issues/28#issuecomment-315559961.
/cc @nunopicado
We have discussed about a way to cache data or object here.
I've created this issue to we continue discussing a way to implement that without using a procedural approach.
@nunopicado thought about a Maybe object, inspired in Haskell. I suggested Laze object in that time, but I'm not satisfied with this name yet.
We already thought about using functions/anonymous functions but this was not completely implemented in Free Pascal.
So, let's come back to scratch and think just in simple objects.
I'm thinking in a simple class called
TCached
. I'll make some drafts and tests. As soon as possible I will publish my results here.