I was asked today:
Could someone please explain the differences between cfc package and public access? I thought that package access made the method available to other templates within the same application, but that doesn’t seem to be the case.
Now, I remember being confused by this when I first started doing CFC’s so figured I would share.
A function with an access of “package” will be restricted to calling CFC’s and templates in the same directory as the CFC file of the function.
In my personal experience, I haven’t found access=package to be terribly useful. I tend to organize my files into subfolders like cfc, and then further subdivide by type of CFC. (Gateway, DAO, utility.) So to access them, I tend to put functions as either public or private. All in all, “package” just makes it harder to work with all of this stuff.
However, I have the luxury of working on private server, and not a hosting provider for the majority of my work, so my view maybe atypical. Anybody have a different viewpoint?
One thought on “CFC’s and Access = Package”
I use package protection sometimes – the trick is in your directory structuring. When I first wrote LightBase, I also put DAOs together, Service classes together and so on.
Then I thought about package protection and realized that you want to do things like make UserDAO only available to UserService to enforce service methods as API. As such, you put UserDAO, User and UserService into model.User. Same for model.product and so on.
That is working out REALLY well for me, so I’ve found that package protection was not only useful, but also helped me to put my files together in what I now find to be a better structure with all of the class files for a give business object in the same directory.