Why does OOP help programmers develop loosely coupled application?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Why does OOP help programmers develop loosely coupled application?

  1. #1
    Join Date
    Dec 2010
    Posts
    524

    Why does OOP help programmers develop loosely coupled application?

    As far as I know, there is a reason of encapsulating data inside a class that makes objects loosely coupled?
    Am I correct? Could you please give me an example?
    Thanks
    Jack

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Why does OOP help programmers develop loosely coupled application?

    Quote Originally Posted by lucky6969b View Post
    As far as I know, there is a reason of encapsulating data inside a class that makes objects loosely coupled?
    Am I correct? Could you please give me an example?
    Encapsulation can make a design less complex and more loosely coupled yes. It's because it can reduce the number of parts that are communicating directly.

    Let's say the design has four parts 1, 2, 3, 4. If all parts communicate they can communicate in 6 ways. Now say you hide parts 1 and 2 in a class A and 3 and 4 in B. Then 1 and 2 can communicate, 3 and 4 can comminucate and A and B can communicate. That's 3 ways of communication so the complexity was cut in half (reduced from 6 to 3) and the design became less tightly coupled.

  3. #3
    Join Date
    Dec 2010
    Posts
    524

    Re: Why does OOP help programmers develop loosely coupled application?

    Hello nuzzle,
    why part 1,2,3,4 would have 6 ways of communication? Sorry, having taken allergy drug, feeling extremely dizzy
    Thanks
    Jack

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,202

    Re: Why does OOP help programmers develop loosely coupled application?

    Quote Originally Posted by lucky6969b
    why part 1,2,3,4 would have 6 ways of communication?
    If you have four people in a room, and each person shakes the hands of every other person once, how many handshakes would there be? The first person shakes the hands of the other three, so that's three handshakes. The second person shakes the hands of the other two (since he/she already shook the hands of the first person, we don't count that to avoid double counting), the third person shakes the hands of the fourth... and tada! 6.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    May 2009
    Posts
    2,413

    Re: Why does OOP help programmers develop loosely coupled application?

    Quote Originally Posted by lucky6969b View Post
    why part 1,2,3,4 would have 6 ways of communication?
    In addition to laserlight's reply I list here the 6 ways 4 parts can interact,

    1 <-> 2
    1 <-> 3
    1 <-> 4
    2 <-> 3
    2 <-> 4
    3 <-> 4

    After the introduction of classes A and B you have,

    1 <-> 2
    3 <-> 4
    A <-> B

    Note that encapsultion is not the only OO way to decouple designs so they become more loose. Many of the so called OO design patterns do that too. Mediator is the typical example of that.

  6. #6
    Join Date
    Dec 2010
    Posts
    524

    Re: Why does OOP help programmers develop loosely coupled application?

    Alright, many thanks to nuzzle and laserlight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center