I'm new to MVC, DDD and Java (perhaps I'm too newbie in development itself).
I'm struggling to process this huge amount of information that WebServices, REST, DTOs, MVC patterns, Jackson Serialization, Service and Controllers packages are offering all together. I'm kinda fine with the topics separated but when put together, my brain is turning to mashed potatoes.
Here is the question:
Scenario: I have this minimalist design...
Shape* - abstract Class
|
| - Rectangle implements Shape
| - Circle implements Shape
| - Triangle implements Shape
* (has an Enum property stating which shape it represents - I had problems with .getClass() in runtime in the past.
.
public static enum Shapes {CIRCLE, RECTANGLE, TRIANGLE}
public abstract class Shape{
private int id;
private Shapes shapeType;
}
public class Circle extends Shape {
private double radius;
}
I also have their DTO corresponding classes. I have controllers that are waiting for a decision of mine to be written. I have a Mapper Class that will convert Shapes to ShapesDTO.
ShapeDTO - abstract Class
|
| - RectangleDTO implements Shape
| - CircleDTO implements Shape
| - TriangleDTO implements Shape
I'm unable to perceive in which point of my process I'll materialize/instantiate the proper object.
The processes, as far as I undertand is:
- ShapeController receive a request (I will stay with a GET)
- ShapeController call ShapeService to request a list of ShapesDTO
- ShapeService creates a new Instance of ShapeCollection (which only contains an ArrayList of ShapesDTO).
- ShapeCollection desserialize my shapes from XML. (optional step right now)
- ShapeCollection generates a list of desserialized Shapes and convert from Model version to DTO.
At this point my struggle begins:
- Should my Service know what Shape should be Converted to Circle, Rectangle or Triangle?
- Is this a mapper Job
- I'm already thinking about the Post (new Circle) moment.
If you guys could complement your reply with any reading/blog/articles/literature tips that would be also awesome.
question from:
https://stackoverflow.com/questions/65858556/which-layer-should-be-responsible-for-instatiating-the-proper-objects 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…