Remote Synthesis
Search my blog:
Viewing By Entry / Main
Jan 09, 2006

Sincerely, Frustrated with OO in Boston

Dear CF OO Gurus,

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

Comments
Sean Corfield
This is a pretty common stumbling block and there is no "one true way" to solve it. 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?


matty
Dude, I'm right there with ya. I've been looking at Ray Camden's blogCFC code and he's got that .init(something) and a good amount of OOP and it really makes my brain hurt. What really stinks is that it makes me feel like I'm falling behind. Keep us posted...


Kurt Wiersma
I recommend using a service layer to help abstract your DAOs from one another. In your example I would have a userService.cfc that depending on the userDAO, userGateway, permissionsDAO, and permissionsGateway. Then you would have a method called getUser(userid) which would call the userDAO and then the permissionsDAO to load up the user object complete with its persmissions. I have a brief example on my blog (http://jroller.com/page/kwiersma) and hope to post more soon.


Sean Corfield
...and, to be honest, Ray's BlogCFC is really just one big procedural CFC... it isn't even much of an OO application (no offense to Ray and I'm pretty sure he agrees with this assessment).


Doug Hughes
Brian - I like sean's suggestion on how to pass the permissionDao into userDao at runtime. At least that way the userDao doesn't need to know anything more than the interface of the permissionDao. (Blah, blah, blah) 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


Brian Rinaldi
Thanks to all for suggestions! I do like Sean's suggestion. I was actually trying to use ColdSpring to handle that kind of thing, but I think maybe that is like jumping too far ahead at this point. Perhaps it will clear things up a bit by doing things that way and then maybe integrating ColdSpring later.


tom michaels
Boy...is it just me or does Sean have a chip on his shoulder this week?


Brian Rinaldi
Tom, I am not sure what you mean, Sean's comments were very helpful...kidding perhaps? Removing ColdSpring (at least for the moment) and doing things kinda how Sean describes has cleared things up a bit for me. One other quick question...what is the best way to handle a *has many* type of relationship? To use my current example...what if a user has many permissions?


Write your comment



(it will not be displayed)