Re: creaping coupling......
From: Robert C. Martin (unclebob_at_objectmentor.com)
Date: 02/27/05
- Next message: Robert C. Martin: "Re: creaping coupling......"
- Previous message: Bjorn Reese: "Re: MVC in C++"
- In reply to: Mark Nicholls: "Re: creaping coupling......"
- Next in thread: Mark Nicholls: "Re: creaping coupling......"
- Reply: Mark Nicholls: "Re: creaping coupling......"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 08:40:52 -0600
On Fri, 25 Feb 2005 16:41:14 -0000, "Mark Nicholls"
<nicholls.mark@mtvne.com> wrote:
>
>"Robert C. Martin" <unclebob@objectmentor.com> wrote in message
>news:g52t1158vejh1dk89uep1t9cotjk13jqhh@4ax.com...
>> On Thu, 24 Feb 2005 21:22:01 GMT, "H. S. Lahman"
>> <h.lahman@verizon.net> wrote:
>>
>> >It's not you. The basic problem you describe can be summarized as:
>> >physical coupling. The OOPLs do a great job on minimizing logical
>> >coupling between program units but they do a terrible job on physical
>> >coupling.
>>
>> No. A statically typed OOPL does a better job at minimizing physical
>> couplings than a statically typed non-OOPL. A dynamically typed OOPL
>> (like smalltalk, phython, or Ruby) does a *tremendous* job of
>> minimizing physical couplings. It reduces them to near zero.
>>
>> Even in statically typed OOPLS the problem is not that bad. With a
>> good knowledge of OO design principles and design patterns, a designer
>> can reduce physical coupling in C++, Java, and C# to very low levels.
>> Indeed, *THAT* is the reason that OO language, and OO design
>> principles and patterns, are beneficial to the software industry.
>>
>
>You need to demonstrate how to solve the following trivial problem, before I
>will believe that claim.
In C++ it would be trivial to break that source code dependency, as
follows
>
------IWriteable.h-------
>class IElement;
>class IWriteable
>{
> public: virtual void Write(IElement* element) = 0;
>}
-----CPipe.h-------
#include IWriteable.h
>class CPipe : public IWriteable
>{
>...
>}
-----CPipeWriter.h-------
#include IWriteable.h
>class CPipeWriter
>{
> public: void CPipeWriter(IWriteable* writeable)
> {
> ...
> }
>
> void WriteABC();
> ...
>}
----CPipeWriter.cpp----
#include CPipeWriter.h
#include CElement.h
> void CPipeWriter::WriteABC()
> {
> writeable.write(new Element("ABC"));
> }
>
-----main.cpp-----
#include IWriteable.h
#include CPipe.h
#include CPipeWriter.h
>
>IWriteable* pipe = new CPipe();
>CPipeWriter* writer = new CPipeWriter(pipe);
>writer->WriteABC();
In this case main.cpp does not #include IElement.h. In fact the only
source file to #include IElement.h is CPipeWriter.cpp. This breaks
the source code dependency that you were worried about. That's one of
the benefits of the .h/.cpp file division in C++.
In Java and C# you can't do this. The reason is that neither compiler
depends solely on source code. When you compile a .java module, it
tries to find declarations from the .class files that it depends upon.
This means that there is a mixed source and binary dependency. So in
your example above there is no way to keep the source code of
IWriteable from depending on the binary code of IElement.
To be fair, the C++ system also depends on the binary of IElement
since it won't run without it. But in C++ that dependency is not
asserted at compile time. It's only asserted at link time (or runtime
in the case of dlls.). In Java and C# it's asserted at compile time.
The advantage of the C# and Java system is *much* faster compile
times. In C++, compile times cannot get better than O(nlogn) and even
a little carelessness will make them O(n^2). In java and c# compile
times are much closer to O(n) simply because there is no #include tree
to load for each module. So the small extra coupling is probably
worth the benefit.
If you *really* want to get rid of that coupling of IElement to the
main program, you can do it by using reflection. But I doubt it would
be worth it in most cases.
-----
Robert C. Martin (Uncle Bob) | email: unclebob@objectmentor.com
Object Mentor Inc. | blog: www.butunclebob.com
The Agile Transition Experts | web: www.objectmentor.com
800-338-6716
"The aim of science is not to open the door to infinite wisdom,
but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
- Next message: Robert C. Martin: "Re: creaping coupling......"
- Previous message: Bjorn Reese: "Re: MVC in C++"
- In reply to: Mark Nicholls: "Re: creaping coupling......"
- Next in thread: Mark Nicholls: "Re: creaping coupling......"
- Reply: Mark Nicholls: "Re: creaping coupling......"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|