groovy

Private Fields Are Accessible From Other Classes

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.0-RC-1
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

If I declare a private field like this...

Person.groovy
class Person {
   private firstName
}

I can still access this field from another class like this...

Foo.groovy
class Foo {
   def doIt() {
       def p = new Person(firstName:'Jeff')
       println p.firstName
   }
   static void main(args) {
       new Foo().doIt()
   }
}

I don't think that I should be able to access p.firstName inside of the Foo class.

Issue Links

Activity

Hide
Stig Lau added a comment -

"Groovy recipies" has dedicated a whole page (70) to "Groovy ignores the private modifier", and portray this as a functionality of Groovy.
Can you comment on whether Groovy wants to remove this feature?

Show
Stig Lau added a comment - "Groovy recipies" has dedicated a whole page (70) to "Groovy ignores the private modifier", and portray this as a functionality of Groovy. Can you comment on whether Groovy wants to remove this feature?
Hide
Kai G. Schwebke added a comment -

As I do not own "Groovy recipies", what's the rationale in ignoring private? Data hiding is one of the basic concepts of OO programming. A feature would be if it's the other way round: everything's private, public is ignored and access is only possible using get/set methodes (properties).

Show
Kai G. Schwebke added a comment - As I do not own "Groovy recipies", what's the rationale in ignoring private? Data hiding is one of the basic concepts of OO programming. A feature would be if it's the other way round: everything's private, public is ignored and access is only possible using get/set methodes (properties).
Hide
blackdrag blackdrag added a comment -

I always wonder how there can be OO programming in languages that have no concept of private. Ah, well... to answer Stig Lau: As you can see the issue is targeted for 2.0, so 2.0 is the version we are going to fix this by introducing several breaking changes. and the breaking changes are the reason why this is targeted for 2.0.

Show
blackdrag blackdrag added a comment - I always wonder how there can be OO programming in languages that have no concept of private. Ah, well... to answer Stig Lau: As you can see the issue is targeted for 2.0, so 2.0 is the version we are going to fix this by introducing several breaking changes. and the breaking changes are the reason why this is targeted for 2.0.

People

Vote (14)
Watch (8)

Dates

  • Created:
    Updated: