1

Booch gives 4 main concepts (principles) of OOD (see his book Object-oriented analysis and design with applications ):

  1. Abstraction
  2. Encapsulation
  3. Modularity
  4. Hierarchy

Usually we encounter to these 4:

  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance

Are those equivalent? Should I understand Modularity as another term for Polymorphism? As from Booch's definition I don't have that feeling:

Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

As much as I understand here modules are like Java packages. I don't know if this is what Booch means.

1
  • 1
    What definition of polymorphism are you using that makes it seem like it matches the one you posted for Modularity?
    – JeffO
    Apr 7, 2016 at 16:07

3 Answers 3

3

the OO Principles you mention in the first list are guidelines for program design. (there are others aside from those too; SOLID for example.)

OO Principles are a collection of ideas and part of the OO mindset; understanding OO principles such as Abstraction, Encapsulation and Modularity will help you make good design decisions when faced with the task of creating new classes in code.

Some of those decisions might include

  • What name do I choose for a class or Method?
  • Which class does a Method or Field/Property belong to?
  • Should I add this line of code to a Method or create a new one?
  • Should a class be split into multiple separate classes?
  • Should two classes be merged together?
  • Which other classes should have access to a class' interface?

On the other hand, Polymorphism and Inheritance are not principles but language tools; just as for and while are language tools.

While they are often cited as being the defining language features of OO Programming, that line of thinking is somewhat misguided because they can be used in ways which grind against a lot of OO principles. A lot of exceptionally good OO code has been written without using inheritance or polymorphism.

There are occasions when inheritance and polymorphism are useful tools, just as there are occasions when do..while or switch are useful tools; and you should certainly understand what they are and how/when to use them.

However it's a mistake to consider either Inheritance or Polymorphism as OO principles, or that they are 'goals' to work towards. The reality is that they can and frequently are abused, resulting in bad code (usually by programmers who assume that any use of inheritance is a good thing, or who treat inheritance as their go-to tool for code reuse).

3
  • Do you think this article is covering wrong things? codeproject.com/Articles/1069111/…
    – Narek
    Apr 8, 2016 at 9:53
  • @Narek It has a lot of good advice (with the caveat that advice/guidelines aren't hard and fast "rules"), but uses contrived examples which are always something to be wary of. Most real-world problems can't be neatly abstracted into a heirarchy such as Vegetable / Cabbage / Tomato, but that heirarchy at least illustrates language features. The article covers a handful of patterns which might be useful in some way, but every problem will have its own nuances, and probably won't fit into any of those neat contrived examples. Apr 8, 2016 at 10:25
  • @Narek in fairness to the article, its title is "OO basics" - it doesn't seem to be trying to pretend to be a complete guide to OO design, it's trying to introduce some basic concepts; but its missing out quite a lot of information. It might be worth reading some of the links on this page: blogs.msdn.microsoft.com/cdndevs/2009/07/15/… There's a lot of information out there about OO design, so don't worry if you don't absorb all of it at once. Apr 8, 2016 at 10:35
2

Modularity and polymorphism are not the same thing.

Polymorphism lets you have a reference to some type of interface (I use the word in a language-agnostic sense) without knowing or caring (being coupled to) the implementation. It lets you modify the behavior of code by changing what types/implementation you use.

Modularity is, as is stated in your quote, a measurement of how well divided into chunks your code is. Very roughly, if different parts of your system can be swapped out without breaking unrelated stuff, the higher your modularity is. It's about building complex things from simple ones, instead of building a big complex thing from the get-go.

The two are sometimes related (polymorphism is a great tool for decoupling which can help to reach higher cohesion which can lead to higher modularity, but they are not the same thing, and one does not necessarily imply the other.

-1

no 3 and 4 are not equivalent. Polymorphism and Modularity as stated in another answer are very different things. And class inheritance is a way modern programming language offer to achieve hierarchy by a "is a" pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.