[Tutor] Creating a pojo in python

Danny Yoo dyoo at hashcollision.org
Mon Feb 9 08:44:15 CET 2015


On Feb 8, 2015 11:21 PM, "rakesh sharma" <rakeshsharma14 at hotmail.com> wrote:
>
> How can one create a POJO in python.I mean a class like this
> class A {   private a;   private b;   public getA() {       return a;
 }   public getB() {      return b   }}
> I tried creating class in python but the variables were accessible as
public data members.

The acronym POJO stands for "plain old Java object", so technically
speaking, Python style won't encourage what you're trying.

Traditionally, if you add an underscore as a prefix to your field name,
other programmers are supposed to pretend that it is private. This is
conventional.  If you are an advanced user, you can look into properties
which can be used to lock down access more thoroughly.  But for most users,
using the underscore convention is enough.

Can you explain more why you are trying to do a POJO?  In Java, POJOs are
used because of the desire to manage the access to data exclusively through
method calls.  But we can get this in Python with properties, without doing
the exact same thing as Java.


More information about the Tutor mailing list