Should I learn to implement OOP in C? Are there projects that use OOP in C?

前端 未结 6 628
闹比i
闹比i 2020-12-28 17:50

Recently, I finished reading K&R with its, almost all, exercises and examples. I was planning to move to \"Accelerated C++\" that I came across Axel Schreiner\'s book OO

6条回答
  •  礼貌的吻别
    2020-12-28 18:17

    Implementing OOP in C, is it really used? Or its just for mental exercise?

    Yes, it's really used, but unsurprisingly, it's not as common as OOP in languages that were designed for it.

    Are their any existing C projects that use OOP?

    I can remember using a couple:

    • GLib GObject System
    • GTK+ GUI framework

    When it is a good idea to use OOP in C?

    Some problems are very well modeled by OOP. GUIs, for example, are often designed with inheritance between window types, using polymorphism to override and specialize behavior.

    You should use OOP whenever your problem has a beautiful OOP solution. With the footnote that you shouldn't stick 100 lines of OOP code in a 15000 line project, just because it's "kewl"! :)

    Should I invest my time in it?

    That really depends on what you plan to do with it. I'd never advocate not learning anything - it's great to get exposure to how, why and when to use it. It's great to see a language that wasn't designed for OOP support OOP. You read the book, so I assume you have some affinity to C and interest in OOP. Give it a shot, maybe throw together some GUI applications in GTK+. On the other hand, if you're looking to become the next design patterns master web developer, it's probably not the best approach, you may consider other languages that are more focused toward that area.

    So what would you suggest?

    I'd suggest you use the best tools at your disposal that fit the problems you're trying to solve. Decide what problem you're going to solve. A GUI desktop app, a web server, a game, a cmd line utility... once you decide on your problem, you'll be able to better decide which technology fits for developing a solution. I've found that you can't really master anything with "toys", so you need to be doing something real.

提交回复
热议问题