avoiding if statements

前端 未结 24 752
心在旅途
心在旅途 2021-01-30 08:39

I was thinking about object oriented design today, and I was wondering if you should avoid if statements. My thought is that in any case where you require an if statement you ca

24条回答
  •  清歌不尽
    2021-01-30 09:30

    My two bits here of what I understand of the Object Oriented approach -

    First, what objects in a program should be intuitive. That is, I should not try to create a 'Arithmatic' class to provide mathematical functions. This is an abuse of OOD.

    Second and this is a very strong opinion of mine. It should not be called Object Oriented design but Object and Method Oriented design! If the method names of the objects are themselves not intuitive then inherited objects might end up reimplementing the methods already available.

    Object Oriented approach, according to me, is not a replacement for the Procedural approach. Rather it is mainly for two main reasons for the creators of the language -

    1. Better capability of scoping of variables.

    2. Better capability of garbage collection rather than having too many global variables.

提交回复
热议问题