• 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

Class Modeling

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have scoured the internet and a number of books, but am unable to find out how to model a specific concept.

A customer can book a hotel room directly using an internet website. (Easy to model: Customer -> Reservation)

But what if you wanted to model both of these cases:
A customer can book a hotel room directly using an internet website OR A customer can book a hotel room through a travel agent. In this case, I have two associations between Customer and Reservation.

1) Association One

Customer
|
| {noTravelAgentUsed}
|
Reservation

2) Association Two - (n-ary association)

Customer
|
| {usedTravelAgent}
|
|---Travel Agent
|
Reservation

So in the first association, I have a guard indicating that a Travel Agent isn't used. In the second, a guard indicating that a Travel Agent is used.

Does this make sense? Are there any better ways to model this? Is there a way to get rid of the n-ary association which makes the diagram more complex? I was thinking of a CustomerProxy class, but I wasn't sure how to fit this in correctly.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this differentiation is important to you, you could - for example - use an association class:



But that's just one way to model it.

What is your purpose of creating the model? How will it be used, and by whom? Why is the difference of the reservations important in this model?
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ilja,
Thanks for the quick replay. You pose an interesting alternative. I'll have to see if it fits in with the rest of my conceptual model.

I got to thinking about this issue after reviewing the Applying UML And Patterns book (Third Edition). In the book, they have both cases, but not together.

What do you think of my solution. Can you think of a way that doesn't use an association class? I'd like to make this as simple as possible.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the agent important to the relationship between the customer and the reservation? The agent might establish the relationship, but after that does the agent matter? I guess that was Ilja's question, wasn't it.

Is there a relationship between customer and agent as well?
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Travel Agent is only used in the reservation process. That would indicate to me that it could be an association class, but I do like Ilja's suggestion.

Any other thoughts on how this could be setup? If the Travel Agent were used outside of the reservation process, how would that potentially change the model?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are certainly dozens of ways to model it. Again, what will you be using that model for? Whom is it supposed to communicate to? The answers to those questions will be critical to decide what kind of model to create, and how...
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the ambiguity. I don't really have a particular audience in mind other than myself. I am just trying to figure out some approaches to this problem. The examples that are provided above really help to solidify a couple of ways that this can be modeled. Much appreciated.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Terry McKee:
Sorry for the ambiguity. I don't really have a particular audience in mind other than myself.



So you are the audience - that's fine!

I am just trying to figure out some approaches to this problem. The examples that are provided above really help to solidify a couple of ways that this can be modeled. Much appreciated.



So you are using the models to imagine different ways to code the solution to the problem? Or something else?
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ilja said ...

There are certainly dozens of ways to model it.



Brings back memories of our first attempt to use OO modeling. We found that any time you think you have a really great model you can always and forever come in the next morning with a fresh idea and change it again. Analysis paralysis in action. Or inaction.

If you manage dependencies well you can quickly get to a "pretty good" design and tweak it as you go. Finding the "best design" before you code is not a practical goal most days.
[ August 26, 2007: Message edited by: Stan James ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic