In OOPhoto, my latest attempt at learning object oriented programming in ColdFusion, I call Validate() on my objects. This, in turn, calls Validate() on the appropriate Service object and passes itself (the original bean) in as one of the arguments. Validate() is a function that decidedly must know more about the "world" than the object at hand. Therefore, there are parts of validation that must happen outside of the target object. And yet, I have allowed myself to call Validate() on the bean itself as a matter of convenience.
Regardless of the implementation (the indirect call to the Service layer behind the scenes), from the API's viewpoint, it appears that the Bean must know more about the world that just its own data. So, this begs the question: if I do this for the Validate() method, why not for the Save() method as well? Save() is an action that requires not only information about the object but also about the implementation of data persistence in the application. As such, Save() is not something that the object does or should need to know about. Right? I mean the object just needs to know about its own data; persistence should be the responsibility of a different "aspect" of the model.
So, to reiterate, if both Validate() and Save() aspects of the model needs to know about more than just the given bean, why is it that I put Validate() in the bean and leave Save() in the service layer?
The quick answer is, "I don't know."
This is a perfect example of uninformed decision making - of ignorance. I made an architectural decision in my application and I can't explain why I did it. I have brought much shame on family.
I think what this really exemplifies is that I don't understand the principles at play. I believe that what I did was put a Validate() method in the bean to make my objects appear "smart" because, hey, aren't objects in true object oriented programming supposed to be smart and idealized? Perhaps I hoped that if my objects looked enough like OOP-style objects, then maybe my application would be an OOP application.
But the fact is, I can't have it both ways. I can't mix and match the placement of my functionality. I need consistency. I crave it and the sense of order that it provides. I need to either have all of my "smart" methods in the service layer or have them all in the beans themselves. But which is it? If I put them all in the object, then my programming will be shorter and easier to write. But, I don't want my decisions to be based on laziness - if I have to get a reference to the Service layer whenever I want to do something "smart," then so be it. If I put all of my "smart" method in the Service layer, then my programming will be more verbose, but there will be a much better separation of Concerns.
Is it 6 of one, half a dozen of the other? I think both approaches have object oriented programming principles behind them. With smart methods in the Bean, my objects appear smarter and more idealized, a clear aspect of OOP. However, with the smart methods in the Service layer, I am dealing more with processing-based mentality in which I ask objects to "process" the beans, another aspect of object oriented programming.
You may think I am making too big a deal of such a small decision, but really it is quite appropriate. What we are discussing here is a core architectural question that will influence every object that gets created going forward. I will need to go back and think about this carefully.