Andrey Aurora
About
-
Posted Answers
Answer
If using inheritance is a means of reducing code duplication, I'm a little reluctant to have DTOs inherit from anything at all. Inheritance implies an is-a relationship between child class and the parent.
Using audit fields as an example, would you say the following statement is true?
It sounds kind of funny to me when I read it out loud. Inheritance in DTOs becomes problematic, because you introduce coupling between classes where each class usually represents a concrete idea or use case. DTOs sharing a common parent class implies the class hierarchy will evolve at the same time, and for the same reasons. This makes these classes harder to change without having a ripple effect cascading to classes where the new fields might not be applicable.
You'll notice this happen more often for DTOs that serialize and deserialize data from sources you have no control over, like a web service owned by another company or team.
That being said, I've found cases where processing a DTO can be abstracted away. Audit fields are a good example. In these cases I've found interfaces to be a much more robust solution than a concrete parent class, for the simple fact a DTO can inherit from multiple interfaces. Even then I keep the interface as tightly focused as I can and only define the minimal methods to retrieve or modify a small subset of fields:
Now if we go back to our is-a test:
The statement makes more sense. With the use of interfaces it becomes easier to utilize polymorphism in the classes that process DTOs. Now you are free to add and remove interfaces as you see fit to aid in processing the DTOs without affecting the serialization and deserialization to and from their source format. Because interfaces are being used you can modify the classes to reflect structural changes in the data, and have additional methods that make the DTO more palatable to the classes processing them.
Going back to audit fields, you have one web service call a property creatorId and another one calls it createUserId. If both DTOs inherit from the same interface, then processing both of them becomes easier.
Let's say you have a sales staff web service. By coincidence the property names in the XML response match the Auditable interface, so nothing extra is needed in this class:
The customer web service returns a JSON response and two fields are named differently than what is defined in the Auditable interface, so we add a couple of getters and setters to this DTO in order to make it compatible:
Answer is posted for the following question.
Answer
- Avoid Excessive Stress and Anxiety.
- Avoid Ejaculation for Three Days.
- Ask About Possible Hormone Stimulation.
- Ask About Sperm Washing.
- Eat Healthy.
- Exercise Regularly.
- When to Reconsider IUI After Repeated Failure.
Answer is posted for the following question.
Answer
One of the biggest advantages of the Airtel Xstream Fiber wifi is the wide range of plans it offers – from regular use to super high speed
Answer is posted for the following question.
Benefits of airtel xstream?
Answer
You can find your downloads on an Android device in your My Files (or File Manager) Check out the products mentioned in this article:
Answer is posted for the following question.
Hi Can you answer How to download ycheck?
Answer
Select the column to the right of the page break. On the Page Layout tab, in the Page Setup group, click Breaks, and then click Remove Page Break .
Answer is posted for the following question.
How to remove page break in xls?
Answer
- Madison, SD.
- Watertown, SD.
- Brandon, SD.
- Marshall, MN.
- Sioux Falls, SD.
- Huron, SD.
- Mitchell, SD.
- Worthington, MN.
Answer is posted for the following question.
How far is brookings from sioux falls?