aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Problems with needing to construct object in different ways with same constructor args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Problems with needing to construct object in different ways with same constructor args" Watch "Problems with needing to construct object in different ways with same constructor args" New topic
Author

Problems with needing to construct object in different ways with same constructor args

Theodore David Williams
Ranch Hand

Joined: Dec 21, 2009
Posts: 102
I have a class that will have a couple of 'parsers'. These parsers are responsible for parsing a string into a certain class



Ok so assume a vin number has letters in it so it has to be a string not an integer/number.

I want to be able to create my garage with a cars vin, or my cars make/model. Once I have created the garage, I want to be able get my cars make/model or vin. So I want to be able to construct the garage with a vin or a make model, but obviously I cannot have two constructors with the same String argument.

Basically I want be able to go from
car -> makeModel
makeModel -> car

car -> vin
vin -> car

Which is why I have those parsers, but how do I get a car object inside my garage and still be able to go back and forth?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

I don't understand that. The "parsers" are simply tools for creating objects, aren't they? If you want to keep track of the created objects and their relationships, you would need some other tool for that.

If I were designing a system involving cars and VINs then a car would have a VIN. This would give me a mapping from car to VIN. If I wanted the opposite mapping then I would build a Map<String, Car> to provide that.

Such a Map could of course be updated by the factory methods which create Car objects or by the Car method (or constructor) which assigns a VIN to a Car.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with needing to construct object in different ways with same constructor args