Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been programming in python and Java for quite a number of years and one thing I find myself doing is using the setters and getters from Java in Python but a number of blogs seem to think using the dot notation for access is the pythonic way.

What I would like to know is if using dot to access methods does not violate abstraction principle?

If for example I implement an attribute as a single object and use dot notation to access, if I wanted to change the code later so that the attribute is represented by a list of objects, that would require quite some heavy lifting which violates abstraction principle.

share|improve this question
Public properties are more often considered a violation of encapsulation rather than abstraction. It's unlikely that the change you posit would make sense without more changes to the API (e.g. a change to the property or method name at the least) of the object in question. Possible duplicates:…,… – Mike Partridge Oct 31 '12 at 12:43

It depends :-). If you treat the . notation as a shortcut for a public getter, then personally I have no issue with that. However, having everything publicly accessible via the . notation by default in my opinion is a mistake. Not all fields should be automatically visible to the outside world.

share|improve this answer
and if you don't mind refactoring and recompiling in unlikely event of introducing actual getter. Sometimes its ok (you are only consumer of such object), but sometimes you don't even know who is using previous version. Not needed mutability is bigger issue compared to imagined vs actual getter and setter. For final imutable/primitive fields (of value objects) it is mostly good to make them public. – user470365 Nov 15 '12 at 13:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.