Techlog #3. Experimental. Basic concepts. Classes [en]
Added 2023-06-01 14:02:10 +0000 UTC
A small addition to the first article about classes in python.
Earlier, an example was given of how I assign a value to a field through a method that I myself defined inside the class. As it turned out, this is not really a Python-way.
Python, like any other OOP language, has built-in methods for creating getters and setters for fields within a class.
getter - a method for getting the value of a field.
setter - a method for assigning a value to a field.
I immediately started refactoring the game after I found out.
@property_name.setter is our setter.
Well, since, in my case, Quest and QuestStep have an almost identical structure, I moved all the logic into a separate QuestEntity class.
And I simply inherit this entity itself in the class that I put into practice.