Properties in python are used to provide access methods to change an attribute of a class. By providing getter, setter, deleter methods, properties provide abstraction over the internal representation of the data. Property functions can range from data type validation, to any enrichment and calculation.
By adding a
@property decorator, a method in python can be accessed like a variable. Any processing can be performed at the retrieval or at the setting of value. Sample of a class with a property.
Following are few flavors of properties.
Validation In Property
Before setting a property value, we can perform any validation for data type, data range etc and throw an exception in case of failures.
A property can also be declared abstract by using @abstractproperty decorator. This enforces the subclass to provide an implementation.
Constant (Final ) Property
A property can be used to create constants in python. This can be achieved by returning a constant value from a getter, and not declaring a setter method.
Declaring A Property Without Decorator
A property can also be created by declaring getter/setter methods and then passing them as argument to
An adept programmer with experience in design, development and deployment of multiple application routines. Knowledge of various software designs paradigms, development frameworks, deployment methodologies, database modelling and process migration. Special focus on business driven design, search optimization, user interface, data access and data storage implementation. A hacker with a penchant for making technological processes more readily and comprehensively accessible.