• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Silly Question on OOD

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SCEAs and SCEAs to-be!
Another question, which seems very simple but on which I am very uncertain:
Imagine you have two classes, e.g. Customer and CreditCard and the Customer can only have one CreditCard. So you have an 1:1 association "owns" between Customer and CreditCard and navigability in both directions.
I am uncertain if I have to show the customerID as an attribute to CreditCard or if this is done implicit???
What do you think?
Roger
SCEA to-be
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rodger,
First, I don't think you will want navigability going both ways. Which transactions would start with a credit card object? Many will start with a customer object. It is reasonable to associate a credit card with a customer. An association implies that the cutomer object holds a reference to the credit card object in the customer object as a member.
Also an order object may associate customer and implicitly the credit card object together with order items or something else....
Also, having the navigability go both ways has implications for the design of the dv schema. It is more expensive to provide all the additional keys for bidirectional associations.
There are cases where bidirectional relationships are necessary. These are often many to many relationships which require an association class and a extra db table to support.
Noel
SCJP, SCWCD, SCEA(Part1)
 
Roger Zacharias
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Noel!
Roger
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we show these assoication as an aggregation.?
 
noel angel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ratha,
It would technically be correct but if you start down that path: Customer has a credit card and customer has an address what will happen is you will discover that the entire system is a "has a" relationship. You will lose a lot of information that associations provide. Hence, this is one of the arguments for using only associations in a class diagram!
Noel
SCJP, SCWCD, SCEA(Part 1)
 
noel angel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ratha,
By the way: no one does it that way either. Remember that aggregation IS a form of association.
Noel
 
Roger Zacharias
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>First, I don't think you will want navigability going both ways. Which >transactions would start with a credit card object? Many will start with a >customer object. It is reasonable to associate a credit card with a >customer. An association implies that the cutomer object holds a reference >to the credit card object in the customer object as a member.
Hi Noel,
ok we have Customer ---> CreditCard and:
class Customer {
String custID;
String name;
String address;
...
Collection creditCards;
}
and
class CreditCard {
String ccID;
String number;
String type;
}
OK?
But in the DB schema you have the foreign key "custID" in the CreditCard table and no foreign key in the Customer table. So its a kind like
Customer <--- CreditCard.
I am right?
Roger
 
noel angel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rodger,
Yes, you are correct but I still maintain that you would not need to traverse the relationship from credit card to customer.

Noel
 
I AM MIGHTY! Especially when I hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic