Sincerely, Frustrated with OO in Boston
In previous posts, I have talked about how I am trying to move to an object-oriented style of application development in ColdFusion, but I continue to be frustrated by this. I think I have studied the concepts and have a solid general understanding of both the needs and benefits of coding this way. It is the transition from concept to actual implementation that is frustrating me (and makes me feel as if I have generally misunderstood the concepts after all). This isn't a problem with OO, it is a problem with me...I will readily admit that. I mainly get stuck in the same place on each attempt - managing relationships. By this I mean, managing the relationship between an object and its DAO and Gateway and managing the relationship between related objects. For my current example, I have a user that has a set of permissions. I figure that my user object *has a* permissions object..I think I get that and have that set up correctly. However, I can populate my user object from the database using my userDAO.cfc, but that does nothing to the permissions object my user has...should it? I feel as if it should, otherwise who cares whether my user object has a permissions object, as the permissions object it has is totally ignorant of what is going on with the user it belongs to... Am I making any sense at all? Ugh. Can someone lead me down the right path here?
Sincerely,
Frustrated with OO
Boston, MA
I'm guessing you have a permissionsDAO / permissionsGateway CFC to load / populate the permissions info for a given user?
It's reasonable for your userDAO to use that / those to load the appropriate permissions object. Ideally, you would tell the userDAO about the permissionsDAO / permissionsGateway objects when you construct it:
permDAO = createObject("component","permissionsDAO").init(dsn);
userDAO = createObject("component","userDAO").init(dsn,permDAO);
Or something similar.
Does that help?
What really stinks is that it makes me feel like I'm falling behind.
Keep us posted...
Two points:
1) OO is hard. The best way I can think of to learn this stuff is to screw it up first... The more you "screw up" the more you'll think of ways arround the problems. Eventually, one day, you'll be doing it without thinking about it and suddenly you're a guru too.
2) If you want to see one possible implementation of what you want to do, look at some of the Reactor-generated objects. They don't adhere perfectly to what you're trying to do, but they're one solution to the problem. (Note: I'm not saying "use reactor", I'm saying look at it and get some ideas.)
Doug

