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

前端 未结 19 1841
悲&欢浪女
悲&欢浪女 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:50

    The constructor should create a valid object. If in your case that requires reading and parsing information, than so be it.

    If the object can be used for other purposes without parsing the information first, than consider making two constructors, or a separate method.

    0 讨论(0)
提交回复
热议问题