Re: How to invert dependency?




Stefan Ram wrote:
I have an interface »lion«:

interface lion {}

And an interface »tiger«:

interface tiger {}

Now, I build a layer »animal« on top of it:

interface animal
implementedby lion, tiger {}
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
interface lion {} interface tiger {}

The lion and the tiger do not know about the higher
level abstraction »animal«. So I am satisfied with this
structure.

But in Java, there is no »implementedby« clause, the
subinterfaces need to declare their »superinterface«
instead, so one has to write:


interface animal {}
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
interface lion interface tiger
implements animal {} implements animal {}

I do not like it that the lion and the tigers now are aware of
another layer residing on top of them and prefer the first
implementation using »implementedby«. I prefer it, because
the lower levels should not depend on higher layers build
on top of them.

I think the, "Lower," and, "Higher," aspect here is causing the
confusion, if only because of the orientation of your graphic; instead
restate this rule as, "Dependencies should be oriented in the direction
of increasing abstraction" (a more general case of the classic,
"Program to an interface, not an implementation").

Animal is a more abstract concept than a Lion, so Lion should depend on
Animal, and not the other way round.

In other words: your graphic is up-side down. It should look like this
(the arrow of abstraction is still going down the page):

Lion Tiger
\ /
\ /
\ /
Animal


..ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition

.



Relevant Pages

  • Re: How to invert dependency?
    ... And an interface »tiger«: ... implementedby lion, tiger ... Thus there is no dependency on "higher layers" because those layers just specify what a Lion intrinsically is. ...
    (comp.object)
  • Re: BEST MANSTOPPER DOG
    ... > animals and have had to learn how to fight for dominance since they were ... > a medium sized doberman pinscher when the doberman nipped one of her pups. ... I think you are wrong there....1 on 1 a tiger beats a lion hands down. ...
    (rec.martial-arts)
  • Re: USC/ND or FL/Arkansas winner in title game .. ?
    ... It is well known that if a lion and a tiger battle, ... I would rank 1 loss USC ahead of 1 loss Arkansas just ... A 1 loss USC will have done a HELL of a lot more then a 1 loss Arkansas ...
    (rec.sport.football.college)
  • Re: Login Problem How Get to Gui?
    ... > BSD/Darwin command line interface. ... > Security Update 2005-007 delivers a number of security enhancements ... > for Tiger systems Mac OS X v10.4.2. ... > v1.0 on Tiger systems should install v1.1. ...
    (comp.sys.mac.system)
  • Another white disease
    ... let the round peg fit into its round hole..and the square peg fit into the square hole. ... Let the lion be a lion, and the tiger be a tiger. ...
    (soc.culture.african.american)