Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes UML: associations of interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "UML: associations of interfaces" Watch "UML: associations of interfaces" New topic
Author

UML: associations of interfaces

Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

what is the best way to express the relationship between two types when for both of them there is an interface and an implementation? Would it be legal to use any kind of relationship at all if there were only the interfaces in that particular diagram?

Here is an example for relations between classes:


Now which of the drawn relations would be correct in the case of having an interface for each class?


This topic has been discussed in the past with the result that any kind of relation between interfaces is illegal. I have to know that for sure, based on UML 2.0.

If we only allow the association DogOwnerImpl-DogImpl in my second diagram, then I see the following problem: That relation implies that DogOwnerImpl references an array or collection of type DogImpl, like Set<DogImpl>. Of course that would not be done; it would have something like a Set<Dog>. Also, if DogImpl had a method getOwner() I wanted a DogOwner as return type, not a DogOwnerImpl.

It would be pretty to have only the association DogOwner-Dog, but is that legal?

Or how about only having the crossed ones, DogOwnerImpl-Dog and DogImpl-DogOwner, with the multiplicity (1 or *) always appearing only where the interface is. Legal? Good idea?

Maybe the problem is that I misunderstand the role of UML in the design and contracts.

Kai
[ April 05, 2006: Message edited by: Kai Witte ]

Kai Witte's business website Kai Witte's private homepage
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

This topic has been discussed in the past with the result that any kind of relation between interfaces is illegal.


Then how would you represent an interface extending another interface?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Scott Ambler
author
Ranch Hand

Joined: Dec 12, 2003
Posts: 608
Relationships between interfaces do exist:
InterfaceB inherits from InterfaceA
InterfaceB has a dependency on InterfaceC (objects of type InterfaceC are passed as parameters into an operation defined by InterfaceB)

- Scott


<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

Originally posted by Vishnu Prakash:

Then how would you represent an interface extending another interface?


I used the term "relation" in the wrong way. generalization and realization are relations as well. Generalization among interfaces is displayed in the same way as among classes.

Kai
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

Originally posted by Scott Ambler:
Relationships between interfaces do exist:
InterfaceB inherits from InterfaceA
InterfaceB has a dependency on InterfaceC (objects of type InterfaceC are passed as parameters into an operation defined by InterfaceB)


since you explicitly named legal relationships between interfaces, do you mean that the ones I used (associations) are all illegal?
Dog-DogOwner
Dog-DogOwnerImpl
DogImpl-DogOwner

Only legal one: DogImpl-DogOwnerImpl?

Kai
[ April 05, 2006: Message edited by: Kai Witte ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Let's use some real examples from JDBC. The Connection interface has a method that returns a Statement. Statemenet is another interface, so the Connection interface has a dependency on and a uses relationship with the Statement interface.

IBM and Oracle and every JDBC vendor has their own implementations of Statement and Connection. I wonder if they made things so the IBMConnection does not depend on the IBMStatement, so the dependency relationships are:

Connection ---> Statement
IBMConnection ---> Connection
IBMStatement ---> Statement

But what if IBMConnection does a new IBMStatement() somewhere. Then it would also have the dependency:

IBMConnection ---> IBMStatement

Is that bad? Probably not. No cycles, no truly new relationships. It could be avoided with dependency injection or a factory.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

thanks a lot for the replies; they were all very helpful.

Although none of us said it clearly, it seems like most of us suspect that an interface cannot be part of an association. I did not find a strong statement about that in the UML 2.0 specification; it rather is an implication from the definition of "association".

I think the term "dependency" is perfectly clear now.

In my example the only legal associations and dependencies would be:


This assumes a certain implementation of DogImpl and DogOwnerImpl, though, which shows that an association is something that is closely related to an implementation. It is not important when one talks about the contracts and the overall design.

My impression also is that associations are not important in the design phase of a software project which uses a predictive method where the overall design and architecture is planned before the implementation starts. For example in the design phase of a Waterfall based project no associations would be used in the diagrams, rather lots of dependencies.

(A dependency can depend on the implementation, as Stan said, but unlike an association it is not exclusively part of the implementation domain.)

What do you think about that?

Kai
Scott Ambler
author
Ranch Hand

Joined: Dec 12, 2003
Posts: 608
My impression also is that associations are not important in the design phase of a software project which uses a predictive method where the overall design and architecture is planned before the implementation starts. For example in the design phase of a Waterfall based project no associations would be used in the diagrams, rather lots of dependencies.


Design phase? See Development Phases Examined

Associations are incredibly important because they represent very important business rules.

- Scott
 
 
subject: UML: associations of interfaces
 
Similar Threads
PA #1.....picture association
List, ArrayList and Generics as UML
Class Diagram -Association & Inheritance