+ 1
OOP Python Project
How do I organize the code and functions in OOP projects so that it is readable, modifiable and repairable. And how do I know how each class should store its data?
3 odpowiedzi
0
Abd El , Moneim How you divide up your classes and helper functions in Python can vary some.
If your classes are complex enough, you might have one class per .py file.
If a class needs to interact with another class, you can simply import that class from its relevant file.
If your classes are small enough and related enough, it might be better to group them in one .py file.
For example, grouping parent Employee class, and HourlyEmployee and SalaryEmployee child classes all in employee.py file.
Also non-class helper functions which interact with a class might be grouped with the class in a file.
For object data, you need to decide whether it should be public, _protected (semi-private), or __private.
Also whether it needs to be in specific format.
If protected/private or specific format, you want to use @property decorator.
For methods, decide if they are object methods or non-instanced class methods.
Object methods include "self" argument.
Class methods include @classmethod decorator and "cls" argument.
0
at first. relevant and related things you should put in the same class.
come back when you are done, and show what you did.
0
Thank you. I think I almost understood. I'll try to apply what I understood.