Should I use virtual 'Initialize()' functions to initialize an object of my class?

后端 未结 13 1524
孤独总比滥情好
孤独总比滥情好 2020-12-17 14:33

I\'m currently having a discussion with my teacher about class design and we came to the point of Initialize() functions, which he heavily promotes. Example:

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 15:15

    This is a terrible, terrible idea. Ask yourself- what's the point of the constructor if you just have to call Initialize() later? If the derived class wants to override the base class, then don't derive.

    When the constructor finishes, it should make sense to use the object. If it doesn't, you've done it wrong.

提交回复
热议问题