Re: creaping coupling......

From: kirkk (kirk_at_kirkk.com)
Date: 02/24/05


Date: 24 Feb 2005 14:38:32 -0800

I see little wrong with the initial design, aside from the fact that C
is coupled to B. Make C coupled to IB, which also indirectly couples it
to IA. But C is decoupled from all the B's and A's in the world. It can
be compiled separate from them, tested separate from them, and used
only with those you desire.

And if you place IB and IA in the same package or physical unit as C,
but separate the implementations, you'll gain even more flexibility.
Put your interfaces close to the classes that use them. Separate your
interfaces from the classes that implement them.

Kirk Knoernschild
www.kirkk.com
www.extensiblejava.com
Mark Nicholls wrote:
> "Mark Nicholls" <nicholls.mark@mtvne.com> wrote in message
> news:385oe0F5f9jj8U1@individual.net...
> > Is it me, I am being stupid, I keep coming across this
problem......
> >
> >
> >
> >
> > interface IB has a parameter of type IA.
> >
> > class B implements IB
> >
> > and class C instantiates an B....
> >
> > so (in .net though I expect this happens in a lot of strongly typed
> > languages).
> >
> > C has to know about how to instantiate a B.....fair enough.
> > C has to know that about IB.......damn.....why?
>
> ok, well, actually if C ever wants to do anything with B (assuming
the class
> interface B is empty), then C would need to know about IB.....but C
would
> not need to know the details of IB, just that B implements IB.
>
> > C has to know about IA then......disaster......why?
> > etc etc etc
> >
> > Soon C has to reference all sorts of stuff it not interested in.
> >
> > it seems to me that all C should need to know is that some method
> > (constuctor) returns something labelled B.....what you can actually
do
> with
> > B is incidental.
> >
> > Is there a way around this? (OK I could return 'object's and cast
in the
> > code that accesses the interfaces....but uuuuggghhhh)
> >
> >
>
> so let me mildly rephrase.....
>
> C has to know about how to instantiate a B.....fair enough.
> C has to know that about the existence of IB and that B implements
> it.....fair enough.
> C has to know the details of the methods of IB......!....no.....but
my
> compiler seems to reckon it does.
> C thus has to know the interfaces of all parameters in the methods of
> IB....!!......no.....but my compiler seems to reckon it does.
> recursively....!!!!......C has to know the complete tree of
interfaces
> stemming from B.....!!!......disaster.



Relevant Pages

  • Re: creaping coupling......
    ... > is coupled to B. Make C coupled to IB, which also indirectly couples it ... > be compiled separate from them, tested separate from them, and used ... > And if you place IB and IA in the same package or physical unit as C, ... > Put your interfaces close to the classes that use them. ...
    (comp.object)
  • Re: Standard Ada Preprocessor (Was: why ada is so unpopular ?)
    ... The code is all legal Ada except that I have left out the thin C binding ... you need to partition the two as well as ... dependent is separate from the ... interfaces maintained as part of the project in common. ...
    (comp.lang.ada)
  • Re: Circular references not possible?
    ... > Idea of separating interfaces and having the rest of the app depend ... > separate project and localized the object creation to the factory. ... Yes they do;-) even without the Configuration Management application ...
    (microsoft.public.dotnet.languages.vb)
  • Re: design question( the app is written in c# ;) )
    ... completely different layer B for other applications. ... You will generally go to a config driven provider model in this ... 1)If I use interfaces defined in B then it will make it resusable. ... 2)If i separate the interfaces in to a different project then it will ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: divorce and remarriage
    ... that living together before marriage makes the subsequent marriage more ... I think there's good evidence that couples who live together ... before they marry are more likely to separate than ones who ...
    (uk.religion.christian)