c# - Correct architecture for presentation objects that implement same interface -
In the domain model of my project, I have pending classes that apply the same interface: IProduct: Phone, Tablet, DataPackage , Assistant, etc.
I want to display different combinations of this product on different product list pages. This means that I get a list from the layer layer in the presentation layer. And now, I'm wondering what is the right way to force different views for each interface implementation?
I see two ways to do this:
- In the IProduct interface, this method defines how the scene will be selected to display the product. One arm explains the performance logic in this class and smth like the product for each product. Makes a call. Performance () On the other hand, this causes the domain to add some performance logic to the model, which is not good in my view.
- In a presentation level there is a factory that analyzes the type of product and binds the correct presentation.
Which is better? Perhaps there are more patterns to do this?
I avoid the presentation logic mix with my first approach domain classes for. You can add a product type identifier to
IProduct and set the idea of products after a certain plan that includes the product type identifier when showing a view for a product, Make the name and integrate the product type identifier
The advantage of this approach is that you can follow a conference-over-configuration pattern Is not, which does not require clearly configuration, which is mapped to the product of some sort.
For your second approach : Instead of having a big switch statement in a factory that maps a domain class to a view, you can add that registry The scene is assigned to a particular type, it would be better extensible.
Both approaches show the risk that the presentation argument does not provide a view for a new domain class. You have to see that the visual (or registration is respectively) exists for a product type so that it can handle it properly. A possible way would be to provide a default view that shows properties available for all classes in
IProduct Additionally, you should log in to a developer / administrator for a clear error message (see that Whether or not a scene exists)
Comments
Post a Comment