Posts

Showing posts with the label data abstraction

I Take It All Back

My post on Python and data abstraction was mistaken: every example I had seen of using the '@property' feature showed how to control access to a variable with the same name as the property. But last week, and found an example showing that you don't need a variable with the property name at all, so it can, indeed, be used to screen moving a variable into a different class. I stand corrected!

Do Pythonistas Understand Data Abstraction?

I was just reading this page on why not to use getter and setter functions in Python, and realized the author doesn't seem to have any idea what data abstraction is: "In Java, you have to use getters and setters because using public fields gives you no opportunity to go back and change your mind later to using getters and setters." This was never the reason I used a getter or setter method in Java! You use getters and setters to achieve data abstraction : "The representation details are confined to only a small set of procedures that create and manipulate data, and all other access is indirectly via only these procedures." I had a class GridAgent where the agent held its position on a grid, among other things. But then I wanted to re-do this, so that the position was held in a cell, which held the agent. I had (sometimes) done things the "Pythonic" way, but just accessing the position variable, and of course I had to find every instance of th...