Different Method Types
Explore different method types in Python, including public, protected, and private conventions, and understand their implications in PyTorch class design. Learn how to use the setattr function to dynamically add methods to classes and instances, enhancing your code management while recognizing the risks and appropriate use cases.
We'll cover the following...
Different types of methods
In the last lesson, we introduced the methods _make_train_step and _make_val_step and noticed these methods having an underscore as a prefix. Why is this so and how is this different from the double underscore in the __init__ method?"
Let us take a look at why this is the case.
Public, protected, and private methods
Some programming languages like Java have three kinds of methods: public, protected, and private.
Public methods are the kind you are most familiar with; they can be called by the user.
Protected methods, on the other hand, should not be called by the user. They are supposed to be called either internally or by the child class (the child class can call a protected method from its parent class).
Finally, private methods are supposed to be called exclusively ...