Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double length_inches
- {
- get { return length_metres * 39.0; }
- set { length_metres = value/39.0; }
- }
- class Foo(object):
- def get_length_inches(self):
- return self.length_meters * 39.0
- def set_length_inches(self, val):
- self.length_meters = val/39.0
- length_inches = property(get_length_inches, set_length_inches)
- class Foo(object):
- # 2.5 or later
- @property
- def length_inches(self):
- return self.length_meters * 39.0
- # 2.6 or later
- @length_inches.setter
- def length_inches(self, val):
- self.length_meters = val/39.0
- var object = {
- // .. other property definitions ...
- get length_inches(){ return this.length_metres * 39.0; },
- set length_inches(value){ this.length_metres = value/39.0; }
- };
- class Thing
- attr_accessor :length_inches
- end
- class Thing
- def length_inches
- @length_inches
- end
- def length_inches=(value)
- @length_inches = value
- end
- end
- class Thing
- def length_inches
- @length_metres * 39.0
- end
- def length_inches=(value)
- @length_metres = value / 39.0
- end
- end
- TFoo = class
- private
- FBar: string;
- procedure SetBar(Value: string);
- function GetBar: string;
- public
- property Bar: string read GetBar write SetBar;
- end;
- TFoo = class
- private
- FBar: string;
- public
- property Bar: string read FBar write FBar;
- end;
- class Length( object ):
- conversion = 39.0
- def __init__( self, value ):
- self.set(value)
- def get( self ):
- return self.length_metres
- def set( self, value ):
- self.length_metres= value
- metres= property( get, set )
- def get_inches( self ):
- return self.length_metres*self.conversion
- def set_inches( self, value ):
- self.length_metres= value/self.conversion
- inches = property( get_inches, set_inches )
- >>> l=Length(2)
- >>> l.metres
- 2
- >>> l.inches
- 78.0
- >>> l.inches=47
- >>> l.metres
- 1.2051282051282051
- Public Property Get LengthInches() As Double
- LengthInches = LengthMetres * 39
- End Property
- Public Property Let LengthInches(Value As Double)
- LengthMetres = Value / 39
- End Property
- @interface MyClass : NSObject
- {
- int myInt;
- NSString *myString;
- }
- @property int myInt;
- @property (nonatomic, copy) NSString *myString;
- @end
- @synthesize myInt, myString;
- - (void)setMyString:(NSString *)newString
- {
- [myString autorelease];
- myString = [newString copy];
- }
- Public Property Name As String
- Get
- return "someName"
- End Get
- Set
- ...
- End Set
- End Property
- class Length {
- public $metres;
- public function __get($name) {
- if ($name == 'inches')
- return $this->metres * 39;
- }
- public function __set($name, $value) {
- if ($name == 'inches')
- $this->metres = $value/39.0;
- }
- }
- $l = new Length;
- $l->metres = 3;
- echo $l->inches;
- template <class TValue, class TOwner, class TKey>
- class property
- {
- TOwner *owner_;
- public:
- property(TOwner *owner)
- : owner_(owner) {}
- TValue value() const
- {
- return owner_->get_property(TKey());
- }
- operator TValue() const
- {
- return value();
- }
- TValue operator=(const TValue &value)
- {
- owner_->set_property(TKey(), value);
- return value;
- }
- };
- class my_class
- {
- public:
- my_class()
- : first_name(this), limbs(this) {}
- struct limbs_k {};
- struct first_name_k {};
- property<std::string, my_class, first_name_k> first_name;
- property<int, my_class, limbs_k> limbs;
- std::string get_property(const first_name_k &);
- void set_property(const first_name_k &, const std::string &value);
- int get_property(const limbs_k &);
- void set_property(const limbs_k &, int value);
- };
- class MyClass:
- //a field, initialized to the value 1
- regularfield as int = 1 //default access level: protected
- //a string field
- mystringfield as string = "hello"
- //a private field
- private _privatefield as int
- //a public field
- public publicfield as int = 3
- //a static field: the value is stored in one place and shared by all
- //instances of this class
- static public staticfield as int = 4
- //a property (default access level: public)
- RegularProperty as int:
- get: //getter: called when you retrieve property
- return regularfield
- set: //setter: notice the special "value" variable
- regularfield = value
- ReadOnlyProperty as int:
- get:
- return publicfield
- SetOnlyProperty as int:
- set:
- publicfield = value
- //a field with an automatically generated property
- [Property(MyAutoProperty)]
- _mypropertyfield as int = 5
- public int get_SomeValue() { return someValue; }
- public void set_SomeValue(int value) { someValue = value; }
- private int someValue = 10;
- // client
- int someValue = someClass.get_SomeValue();
- someClass.set_SomeValue(12);
Add Comment
Please, Sign In to add comment