• 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

instance and type of instance in a class diagram

 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Driver class which must know the "Type" of car it can drive. And then it must also be assigned an Actual Car to drive. The car must of course be of the same "Type".
e.g. Type of car can be Mustang and a car is identified by it VIN#.
How to best present it in a Class Diagram?

The Actual Car sounds more like an instance than a Class.

Driver<CarType> ----- 1 CarType <|---realize-- ActualCar(-vin#)
does this look right to you?

Is actual car a realization of CarType or an instance?

[ March 12, 2008: Message edited by: Abhinav Srivastava ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that the class design is at least as much driven by the needed behavior in the system as by "real world" structures.

From the little you have told us about the needed behavior, I wouldn't have an inheritance relationship between Car and CarType at all. Instead, I would Car "have a" CarType (that is, use an association), with the latter possibly being some kind of typesafe enum.

Does that help?
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. I concur with you on the Car-CarType relationship.

driver.setAllowedTypeOfCar(CarType);
driver.setCar(Car);

Is there a uml notation using which I can assert
car.getType() == driver.getAllowedTypeOfCar()
other than a Note?
[ March 13, 2008: Message edited by: Abhinav Srivastava ]
 
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
I'd guess that you could do this using OCL. Don't have any experience with it, though.
 
reply
    Bookmark Topic Watch Topic
  • New Topic