Java best practice library creation for flexible class creation (Factory Pattern, abstraction, and interfaces) -


Imagine I'm a Java software developer for a car manufacturer. I have been working with a library that will be used by many in-house applications for each car model created, I create a Java object while presenting that model. Not only should I be able to track the current model, but prototype models. The prototype model will have a name that is likely to change once in production.

My question is, what is the best way for this?

These are my thoughts ...

I am reading many books for ideas so that it can handle this situation better. Immediately my brain jumps to use a factory pattern. I will have a carmodalfactor class, which will return a solid object for each model. For example:

  Public Limousine carmodel factory () {public carmodel settingCivic model () {} Making a public carmodalAcordModel () {} public carmodel formation protocol (1) (new model x); } Public carmodel formation Prototype 1 () {Go back to new model Y}; }   

Will this be the best way? I think the abstraction should be the second layer. I see that the problems are:

1) What if the model's model goes into production, then I prepare a method for it and make some more, the prototype 1 method remains Now, such programs that call, that method is called the wrong object

2) How do I change the model of my model?

I thank you for your time!

The factory model looks good, but I have a createCarModel (string model) I can suggest method, which looks at the right thing in a map, then the name of a car model is changed to simple add / remove it in that map. With appropriate synchronization, to prevent name change and to exit from collision.

The map could probably map & lt; String, Class & lt;? Carmodel's expansion & gt; & Gt; The , and createCar method will trigger the class using a non-logic constructor, in which case you will need all the cars s.

In this way, no one is required to change or rename a model, as the factory class has not set its system signature.

In addition, if you override Class Ooder , you can load an old model and load a new model, so that your classified files are genuine Your classic files can be kept, which can be kept (no older prototype classes that are not in the actual model).

Comments