D
Dave Vandervies
Hi. I'm new to this group. I'm refreshing/learning C++ and am starting to
learn Object Oriented Programming (OOP). In discussing this with people I
came up short as to what the benefits of OOP are. For example: As I
understand it, OOP has its main benefit in software reuse. Thus one develops
a software library of classes and this cuts down the overhead of reinventing
the wheel. Someone might say that this can be done with structured
programming with function libraries. So I have a few questions.
1) For those of you who like OOP, why do you like it?
Because it makes some problems a lot easier to deal with.
In particular, being able to hide the details of how something works
behind a well-defined interface can make it a lot easier to localize the
complexity in a program. (There is, however, a lot more room to make
something go Very Wrong in designing the interfaces than in building
the code that uses the interfaces, so using OO for encapsulation without
paying attention to getting the interfaces right is asking for trouble.)
Besides the encapsulation benefits (which, with a little bit more
discipline, can be had without OO), there are also places where the
polymorphism made possible by the OO model leads to a cleaner solution
than other ways of looking at things would lead to. (F'rexample, any
problem whose solution involves dealing with objects that have different
behaviors but have the same interface and can be sensibly used in the
same places.)
2) Can OOP be accomplished with non-object oriented languages such as C?
Yes. I don't find it as ugly as a lot of people do, but there are a
lot of details you need to keep track of yourself and therefore a lot
of room to introduce errors. If you find yourself wanting to do OOP in
a non-OO language, it's probably time to reconsider either your choice
of tools or your approach.
3) If you're not part of a software engineering team but are programming
from your own use and don't need to reuse code would you bother with OOP?
If it's the right tool for the job.
It won't solve all the world's problems, but there are a lot of classes
of problem where the interface-centric, implementation-agnostic model
makes the solution a lot cleaner (or even makes a solution possible).
If you *really* want to understand OO, I would suggest learning both
an OO language with strong static type-checking (such as C++) and an OO
language where an object's "type" is dynamically determined entirely by
its interface (such as Smalltalk). (`Learning' here means wrapping your
brain around the mindset the language needs to be used effectively, not
just figuring out where the semicolons go.) Be warned that this is not
a trivial undertaking, but seeing (and understanding) the similarities
and differences between the two variants of "object-oriented" programming
languages is Rather Helpful.
dave