How much work should the constructor for an HTML parsing class do?

前端 未结 19 1931
悲&欢浪女
悲&欢浪女 2020-12-23 09:55

How much work is it reasonable for an object constructor to do? Should it simply initialize fields and not actually perform any operations on data, or is it okay to have it

19条回答
  •  暖寄归人
    2020-12-23 10:32

    A constructor should set up the object to be used.

    So whatever that is. That may include taking action on some data or just setting fields. It will change from each class.

    In the case you are speaking of an Html Parser, I would opt for creating the class, and then calling a Parse Html method. The reason for this is it gives you a furture opportunity to set items in the class for parsing the Html.

提交回复
热议问题