Is it acceptable having parameter in class constructor?

后端 未结 3 1062
感情败类
感情败类 2021-01-13 06:33

a rubygem I\'m writing and that is useful for counting word occurrences in a text, I choose to put 3 parameters in class constructor.

The code is working, but I want

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 06:52

    In my experience I can tell that the very reason for allowing constructor parameters in most languages, apart from the fact of increasing the easiness in class instantiation, is to make it easy to use the API.

    Favoring constructor, over getter/setter instantiation, also helps immutability, that is, creating an object thorough its constructor, and not letting anyone modify its properties later on.

提交回复
热议问题