Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - how to implement association relationship in Java

 
Thread Tools Search this Thread
Old 11-04-2006, 02:46 AM   #1
Default how to implement association relationship in Java


Hi,

I want to implement as association relationship in Java. I understand the implementation for this kind of relationship is called "containment". However, I can not find the code for this on the internet. From what is explained on the internet, I believe the code would look something like this:


/*A Car 'has a' Wheel relationship*/

public class wheel{
public wheel(){
}
}

public class Car{
Wheel w;

public Car(){
w = new Wheel();
}
}

Is this the basic idea?
by the way, what does containment mean?

ST






newsnet customer
  Reply With Quote
Old 11-04-2006, 05:27 AM   #2
hiwa
 
Posts: n/a
Default Re: how to implement association relationship in Java
newsnet customer wrote:
> what does containment mean?

Container Car contains Wheel.
Also you could use
Hashtable<Car,Wheel>
or
HashMap<Car,Wheel>
for representing association relationship.



hiwa
  Reply With Quote
Old 11-04-2006, 02:49 PM   #3
JanTheKing
 
Posts: n/a
Default Re: how to implement association relationship in Java
Try an UML tool called JUDE (free) wherein you can create a simple
class diagram to depict association relationship (fairly simple). Then
click on "export to Java" to create the class files. That should
clarify the concept.

Cheers,
Jan

On Nov 4, 10:27 am, "hiwa" <HGA03...@nifty.ne.jp> wrote:
> newsnet customer wrote:
> > what does containment mean?Container Car contains Wheel.

> Also you could use
> Hashtable<Car,Wheel>
> or
> HashMap<Car,Wheel>
> for representing association relationship.




JanTheKing
  Reply With Quote
Old 11-08-2006, 09:05 AM   #4
LaieTechie
 
Posts: n/a
Default Re: how to implement association relationship in Java
On Sat, 04 Nov 2006 02:46:04 +0000, newsnet customer wrote:

> Hi,
>
> I want to implement as association relationship in Java. I understand the
> implementation for this kind of relationship is called "containment".
> However, I can not find the code for this on the internet. From what is
> explained on the internet, I believe the code would look something like
> this:
>
> /*A Car 'has a' Wheel relationship*/
>
> public class wheel{
> public wheel(){
> }
> }
> }
> public class Car{
> Wheel w;
>
> public Car(){
> w = new Wheel();
> }
> }
> }
> Is this the basic idea?
> by the way, what does containment mean?
>
> ST


There are two types of relationships you should concern yourself with in
Java:

Has A: this indicates containment. In you example, a Car has a Wheel.
Your container class should have a member property ("instance variable")
of that type.

Is A: this denotes inheritance. A Car is a vehicle. You indicate
inheritance with "extends" (for classes) or "implements" (for interfaces).

Public class Car extends Vehicle {}

You may also run into "uses" relationships, which may translate into
instance variables or local variables (variables defined within a certain
scope, like a method).

HTH,
La`ie Techie



LaieTechie
  Reply With Quote
Old 11-09-2006, 11:56 AM   #5
Codedigestion
 
Posts: n/a
Default Re: how to implement association relationship in Java
Peace,

I would like some help. As far as I've understood thus far:

a "is a" b = inheritance of 'a' from super('b')
a "has a" b = 'b' is a property of class 'a'

now how can I understand the relationship of an interface to a class,
as in:

'a' implements 'b'

Thanks in advance,
God Bless,

shree

LaieTechie wrote:
> On Sat, 04 Nov 2006 02:46:04 +0000, newsnet customer wrote:
>
> > Hi,
> >
> > I want to implement as association relationship in Java. I understand the
> > implementation for this kind of relationship is called "containment".
> > However, I can not find the code for this on the internet. From what is
> > explained on the internet, I believe the code would look something like
> > this:
> >
> > /*A Car 'has a' Wheel relationship*/
> >
> > public class wheel{
> > public wheel(){
> > }
> > }
> > }
> > public class Car{
> > Wheel w;
> >
> > public Car(){
> > w = new Wheel();
> > }
> > }
> > }
> > Is this the basic idea?
> > by the way, what does containment mean?
> >
> > ST

>
> There are two types of relationships you should concern yourself with in
> Java:
>
> Has A: this indicates containment. In you example, a Car has a Wheel.
> Your container class should have a member property ("instance variable")
> of that type.
>
> Is A: this denotes inheritance. A Car is a vehicle. You indicate
> inheritance with "extends" (for classes) or "implements" (for interfaces).
>
> Public class Car extends Vehicle {}
>
> You may also run into "uses" relationships, which may translate into
> instance variables or local variables (variables defined within a certain
> scope, like a method).
>
> HTH,
> La`ie Techie




Codedigestion
  Reply With Quote
Old 11-09-2006, 01:24 PM   #6
Chris Uppal
 
Posts: n/a
Default Re: how to implement association relationship in Java
Codedigestion wrote:

> a "is a" b = inheritance of 'a' from super('b')
> a "has a" b = 'b' is a property of class 'a'
>
> now how can I understand the relationship of an interface to a class,
> as in:
>
> 'a' implements 'b'


Unless you want to be pedantic, it's essentially the same as the 'is a' for
class/subclass relationship. It tells you that an 'a' is acceptable wherever a
'b' has been asked for.

Still speaking a bit sloppily; the 'is-a' relationship should really be
understood as 'can-be-used-as-if-it-were-a'. E.g: any Mammal can be used as if
it were an Animal. Now with interfaces, what the interface does is specify
what is /needed/ in order to be used as a <something>, so everything which
implements that interface can be used as if it were a <something>.

This could all be made more precise, but it would lead into a discussion of
what wrong with (or at best misleading about) Java's class-based type system,
and I don't think that would help at all just now.

-- chris




Chris Uppal
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute an external software from VHDL? And how to interface VHDL with JAVA? becool_nikks Software 0 03-06-2009 07:08 PM
Live projects on C, C++, Java, .NET for final year students sheetal7853@gmail.com Software 0 10-05-2008 04:20 AM
Java with Asp.net mdinant Software 0 04-04-2008 12:21 PM
Java Beginners Still Bill Software 3 02-19-2008 10:13 AM
Blu-ray Disc Association Surpasses 100th Member Milestone. Allan DVD Video 0 02-16-2005 01:17 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46