pyleecan
pyleecan copied to clipboard
[NF] Generate mandatory methods in abstract class with class generator
The goal of this feature is to automatically define some methods which are mandatory for specific classes.
Let's consider an abstract class "My_Class" and different inherited classes "MyClass1" and "MyClass2". The two classes have a method "my_super_method" in common. For example, sometimes I use MyClass1 with visualisation , and sometimes MyClass2 because it is faster.
To ease the development of a "MyClass3" and bug correction, we would like to write down in the abstract class that "my_super_method" must be available.
Notation idea
The proposition is to use "*" as a prefix in the "Method" column of abstract classes:
*my_super_method
Automatic error msg: Then the class generator must automatically create a file for the method "my_super_method" for the class MyClass which would contain something such as:
def my_super_method(self)
raise InputError('ABSTRACT CLASS ERROR: The ' + str(self.class) + ' class must have a <my_super_method> method.')
I think the notation would help developers spot the main methods in the .csv files, and the error msg would help user to report easily some bugs and/or incomplete workflows.
Feedbacks are welcome !
Hello Raphaël,
thats a great idea. Only, I would propose to not automatically create a method by the class generator. Instead the class generator should raise an error if the method is missing within the inherited class. If the method is missing, it is a clear 'design flaw' and the user shouldn't be bothered by such errors.
Maybe it's good idea to generally check if all the .csv specified methods actually exists.
Best regards, Sebastian