Re: How to invert dependency?
- From: "Ed" <iamfractal@xxxxxxxxxxx>
- Date: 25 Feb 2006 07:35:48 -0800
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
.
- Prev by Date: Re: software architecture/design question
- Next by Date: Re: Can use of singletons denote poor project design?
- Previous by thread: Re: Can use of singletons denote poor project design?
- Next by thread: Re: How to invert dependency?
- Index(es):
Relevant Pages
|