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?
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.
subject: Problems with needing to construct object in different ways with same constructor args