0

I have the following code:

def __init__(self, vocable_file_path, xsd_file_path, word_list_file_path):
    self.vocable_file_path = vocable_file_path
    self.xsd_file_path = xsd_file_path
    self.word_list_file_path = word_list_file_path


def add_values_to_attribute_of_vocables (self, attribute_name, attribute_value, words_attribute_name):
    ... (does the job of adding stuff) ...

Only the add_values_to_attribute_of_vocables method uses the three parameters set in the constructor. I could move them into the signature of the method quite easily. What stops me from doing that is, that the method signature would get quite long and I am not sure if it is a good practice to do it.

I read the following question here on PSE: How does the concept of a class change when passing data to the constructor instead of method parameters?

It makes me think I should put the parameters into the signature of the method, but I am still not sure, if it's the right thing to do.

This is not a black & white question, if there is something fundamentaly bad about the code or my approach, please say so, thanks.

I can post more code, if wanted, but I think the rest of the code is unrelated and might only clutter this question.

EDIT 1:

I now split my code into multiple classes: http://pastebin.com/WpyKY4fa

Should I now move all the parameters to the constructor of the XLDAttributeAdder class?

2

It's a bit of a code smell, and your gut feeling is right about this not being a good solution. But instead of passing the arguments, extract the method and the three parameters into a separate class. This class takes the arguments in the constructor and exposes the one method.

Something tells me that this one method is actually doing something that can be split off into another class and that the class that currently has this method is violating the SRP (Single Responsibility Principle) in having that method. I think you'll find that the extracted method and class perfectly fit a responsibility that should be handled by a single class.

  • Would it help you to judge this matter if I posted the whole code and link it in the question? – Zelphir Kaltstahl Jul 28 '15 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.