General programming question. When to use OOP?

后端 未结 6 2199
没有蜡笔的小新
没有蜡笔的小新 2021-02-11 03:44

My program needs to do 2 things.

  1. Extract stuff from a webpage.

  2. Do stuff with a webpage.

However, there are many webpages, su

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-11 04:36

    You use OOP when it makes sense, when it makes developing the solution quicker and when it makes the end result easier to read, understand and maintain.

    In this case it might make sense to create a generic Extractor interface/class and then have subclasses for Twitter, MySpace, Facebook, etc but this really depends on how site-specific the extraction is. The idea of this kind of abstraction is to hide such details. If you can do it, it makes sense. If you can't you probably need a different approach.

    It may also be that similar benefits can be obtained from good decomposition of a procedural solution.

    Remember at the end of the day that all these things are just tools. Pick the best one for that particular job rather than picking the hammer and then trying to turn everything into a nail.

提交回复
热议问题