Modularity vs Object Orientation
Hi,
I've been wondering what the differences are between modular programming and object oriented programming. I've read Wikipedia on Modularity, however it wasn't very clear to me due to lack of examples.
Could someone emphasize on the difference and similarities between the two, accompanied with code examples? Keep in mind I'm a C++ programmer.
So far my understanding of modular programming is that it is a subset of concepts from OOP, for example: Modularity in C++ would be classes, structs, or global funtions with no polymorphism, virtuals, or inheritance. No V-Tables basically (interface has to be static, which means at compile time you have to know what exact function will be executed).
Object Orientation, to my understanding, is everything Modularity is PLUS polymorphism, etc. Is this accurate?
Thanks for reading.
# 1 Re: Modularity vs Object Orientation
My take on it is modularity is more like how pluggable and replaceable are the modules. I don't think OOP enters into this (although it may inhibit modularity).
In the simplest examples consider throwing all your source code (say C- source code into one big function). Everything to run the program is in the one function and one source file. Not very modular and hard to apply changes.
Now break out the one big function into separate functions. Easier to modify.
To go further, you can break out certain functionality into dll's.
I believe the whole point of this is as the code becomes more modular, changes to a module has (er, should have) minimal impact on other modules.
Moving back to C++. I believe polymorphism/inheritance can be used within a module, but as these language features get used across modules, the 'modularity' of the system is reduced.
It seems like now-a-days we have other terms which don't necessarily replace modularity but are related concepts. These are:
Cohesion (http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29)
Coupling (http://en.wikipedia.org/wiki/Coupling_%28computer_science%29)
Arjay at 2007-11-9 12:19:35 >

# 2 Re: Modularity vs Object Orientation
I understand the idea where it seems inheritance inhibits modularity, however, no matter how many classes inherit from one another modularity still exists in the same way it did before, because if you have three classes that inherit from one, and you modify that one you don't have to change the other three, and if you modify one of the three, you don't have to change the one it inherits from nor the other two.
To be a bit clearer, in modular applications if you take one module out of the app it stops functioning, as with one class where others inherit from it.
The idea is simply to swap out and replace modules.
Inheritance might mean more classes relying on each other but as long as you can swap out classes, modify them and then put them back in without affecting how the rest of the app functions then it remains as modular as ever.
I realise the wikipedia page contradicts this slightly but it looks like a rather simplified view and other journals will provide comment and arguments on this idea. For example look at the work of the creator of modular design:
http://en.wikipedia.org/wiki/David_Parnas
I know he has one very clear article outlining modular programming (I cant remember the title I am afraid (it's been a while!)) - but read the wiki page on him too, it should be useful.