Difference Between Property, Attribute and Methods Object Orientation

Viewed 367

I wanted to get a better understanding of the difference between an:

  1. Attribute
  2. Method
  3. Property

I have created a class call Patient and I have labelled what believe are the methods and attributes:

enter image description here

Where in this code is the Property and if the property is something completely different and I have not included it in my code then using my example how can I include a property?

Also what is a Property of a Class?

1 Answers

There are no properties in your code. You can read this SO Answer to learn more about properties.

In short, they are typically marked by an @property decorator and therefore you can define getters and setters.

By default, every instance attribute has a getter and setter. Getting it simply returns its value and setting it sets the value. Properties allow you to modify the behaviour of these getters and setters and change the value before it is returned/set.

Brackets when creating a class are typically used for inheritance. Blank brackets are the same as not including anything.

Thus, class Person() is functionally identical to class Person.

This means that the class is simply derived from object (you can read more about that here), but you can take it as it is not derived from any parent class.

Related