Re: How to invert dependency?
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Sun, 26 Feb 2006 15:47:44 GMT
Responding to Ram...
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.
Keep in mind that an OO Class Model is not a Data Model. One of the important distinctions is object instantiation. In a Data Model the superclasses and subclasses can be individually instantiated. But in OO, like Highlanders, There Can Be Only One. (An inside joke only appreciated by rather ancient SciFi fans.) That is, in OO subclassing there is only a single object created to resolve the entire tree. That's why OO subclassing is often referred to as an is-a relationship. The object is always a member of /every/ class set in a direct line of ascent from leaf subclass to root superclass.
Think of OO subclassing as a Venn Diagram from set theory. A member object is just one of the dots in the diagram and one identifies the relevant sub-/superclass memberships by the enclosing subset lines. The only reason we use a tree to define OO subclassing is because the subsets are defined in terms of <usually> multiple properties that a subset member has and it is much more convenient to identify the subsets AND the properties that define them in a tree form.
Thus a Lion is-a Animal always so there is no question of it "knowing" about Animal; it /is/ one. Thus there is no dependency on "higher layers" because those layers just <fully> specify what a Lion intrinsically is.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
(888)OOA-PATH
.
- Prev by Date: Re: software architecture/design question
- Next by Date: Re: software architecture/design question
- Previous by thread: Re: How to invert dependency?
- Next by thread: supporting documents templates and tools for ddd?
- Index(es):
Relevant Pages
|