0

In ColdFusion 10 by setting <cfset THIS.invokeImplicitAccessor = "true"> in application.cfc We can now access any property belonging to a cfc directly.

I am not sure why a developer will use this kind of functionality.

My question, is this not violating data hiding principle of object oriented programing?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Deepak Kumar Padhy
  • 4,128
  • 6
  • 43
  • 79
  • this is primarily opinion based, so I wouldn't be surprised if this gets closed, but there's a good write up on Adam Cameron's blog that may help you reach a conclusion http://cfmlblog.adamcameron.me/2013/09/invokeimplicitaccessor-is-quite-cool.html – Matt Busche Jan 03 '14 at 13:49
  • Again - alluding to a similar question you asked last week - you need to ask this sort of thing on a discussion forum, not on S/O. S/O is for questions like "I have this specific problem, I have researched it, here is the evidence, and my testing so far, but I can't solve it. Can you steer me towards an answer". And the questions need to be explicitly answerable without being subjective. This is an excellent question, but not for here. Voting to close. – Adam Cameron Jan 03 '14 at 13:53

1 Answers1

5

Implicit accessors are an established OO-esque (they're really not an OO concept per se; it's just syntactical sugar) concept (see C#'s docs for accessors). This is just the CFML mechanism for switching them on (they are not on by default). I do not see how this has any relevance to "data hiding principles".

All it does is mean instead of doing this:

myObj.getProperty();

One can do this:

myObj.property;

With the latter syntax, getProperty() is still called, it's just called implicitly.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • I mean to say is it not violating encapsulation, as user should not be able to directly access any data members of a class directly – Deepak Kumar Padhy Jan 03 '14 at 16:57
  • 1
    @DeepakKumarPadhy - Look over the link Adam posted and you will see it not *really* accessed directly. It is different than making a variable `public` or `protected`, which is what you are describing. The accessor concept is ultimately just a shorter way of writing `get/setProperty()`. – Leigh Jan 03 '14 at 20:39
  • Sure , I will check that. – Deepak Kumar Padhy Jan 04 '14 at 02:40
  • Yeah, if yer gonna ask a question, you actually need to read the answers / other info provided. Otherwise we're just wasting our time. – Adam Cameron Jan 04 '14 at 12:10