pyleecan icon indicating copy to clipboard operation
pyleecan copied to clipboard

[NF] Generate mandatory methods in abstract class with class generator

Open RaphaelPile opened this issue 5 years ago • 1 comments

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 !

RaphaelPile avatar Jun 22 '20 15:06 RaphaelPile

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

SebGue avatar Jun 23 '20 09:06 SebGue