Inheritance in ColdFusion: Private is more like Protected

We are beginning to utilize inheritance with ColdFusion in one of our new applications we are building currently at work.  We have some parent classes that really have few, if any, methods that should be initialized directly as they where designed to be extended by various other classes.  I realized I wanted some sort of access to use for these methods similar to Protected access in Java.  In the past, I tried to utilize the Package access that ColdFusion supports, but that ended in disaster as I did not do my homework and it did not truly understand what it means for two classes to be in the same Package.  I’m not sure if this changed or I just read it wrong, but it turns out that Private access in ColdFusion is not implemented the same as it is in many other languages.  My understanding of Private in most languages is that the access is limited to the immediate class and nothing else.  it turns out that in ColdFusion it is actually accessible within the immediate class, but also available to any of it’s subclasses.  This was good news as it offers a solution that I was looking for.  However, it poses a new question.  Is there no truly private access in a ColdFusion component?  I have heard mention that the variables scope is private as well, but upon running some tests, confirmed it is private to the extent of the private access used for functions which means again, that is is available to a class’s subclasses as well.

One one hand, I am delighted to find that I can protect methods in my parent class, but on the other, I am left wondering what would one do if they wanted a private method or attribute in a ColdFusion class.  If anyone has any insight on this, please let me know!

Leave a Reply

You must be logged in to post a comment.