473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

About Encapsulation

Hey folks,

I wanna know more about encapsulation in python. Is it fully suported?
How can I define the encapsulation statements for methods and attributes?

Regards!

[]'s!
--

Adriano Monteiro Marques
www.gopython.com.br
py********@gmail.com

I'm FREE... Are you?
(PYTHON powered)
Jul 19 '05 #1
2 4177
You mean private, protected, public, that kind of stuff ?

They do not exist in Python. Conventionally if you don't want
the user of a class to access a method or attribute, you use
the prefix _ ;

class K(object):

_a = 1

def __init__(self, val):
self.arg = val
self._hidden = 1

def _method(self):
pass
The _hidden attribute can still be accessed by ...
h = K()._hidden


.... but hey ! You know you *should* not. It's the
"we are all consenting adults" philosophy of
programming.

By the way, K._method and K._a won't appear
in the (py-)doc of the class ...

Cheers,

SB

Jul 19 '05 #2
Adriano Monteiro a écrit :
Hey folks,

I wanna know more about encapsulation in python. Is it fully suported?
How can I define the encapsulation statements for methods and attributes?


If you're thinking of things like private/protected/public:

class Foo(object):
def __init__(self):
self.public = 'this is the API'
self._protected = 'implementation detail'
self.__private = 'keep out'

BTW, you may want to have a look at this:
http://c2.com/cgi/wiki?Encapsulation...ormationHiding
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: .pd. | last post by:
If I have a control that adds itself to its container, does that break encapsulation? Is it a bad thing? Here's what I mean: public class fred { public barny b; public fred() {
7
by: Tony Johansson | last post by:
Hello! A friend of mine asked me the following question that is quite difficult to answer. He use only C and can't find any problem with it. Which problem is there when not using an OOP in...
5
by: jmsantoss | last post by:
Hi, This is a design question. I have a class named "DataBuffer" that stores some data. After "DataBuffer" is created it can not be modified. All the methods of "DataBuffer" are const as data...
47
by: Roger Lakner | last post by:
I often see operator implemented something like this: class Foo { ... }; class FooList { public: const Foo& operator (unsigned index) const {return array;}; Foo& operator (unsigned index) ...
19
by: fyhuang | last post by:
Hello all, I've been wondering a lot about why Python handles classes and OOP the way it does. From what I understand, there is no concept of class encapsulation in Python, i.e. no such thing as...
32
by: bluejack | last post by:
Ahoy: For as long as I've been using C, I've vacillated on the optimal degree of encapsulation in my designs. At a minimum, I aggregate data and code that operate on that data into classlike...
17
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code...
14
by: JoeC | last post by:
I have been writing games and I also read about good programming techniques. I tend to create large objects that do lots of things. A good example I have is a unit object. The object controls...
16
by: copx | last post by:
I have recently read "Everything you ever wanted to know about C types" by Peter Seebach (1), and learned about incomplete types. Now, I realise the value of encapsulation, but I wonder whether it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.