Using Plants in Presenters in Model View and Presentation Design with Model View

In domain driven design, it seems to be good practice to use factories to create your domain objects at your domain level (as opposed to using a direct constructor or IoC).

But what about using domain object objects at the presenter level. For example, let's say that I was creating a domain object from user input received from the presenter.

Here's an example, let's say I have a config domain object that has multiple decimal settings.

public class Configuration: PersistantObject {

 public decimal temperature {get;set;}

 ...(times 20)

 public decimal gravity {get;set;}

      

}

To create this object in the domain layer and not at the presenter level, I would have to pass each of these decimal values ​​as parameters to the function. Create an unmanaged function definition and call.

those. ConfigurationService.CreateConfiguration (temperature, ... (x20), gravity);

Perhaps a better solution would be to create a Configuration object at the presenter level and assign all values ​​to the configuration object directly from user input, skipping the lengthy function call.

Configuration config = ConfigurationFactory.CreateNewConfiguration ();

config.temperature = temperature;

.. (x20) .. = ...;

config.gravity = gravity;

ConfigurationService.SaveNewConfiguration (configuration);

But I'm wondering if this approach is wrong and why? If both of these approaches are wrong, what is the best approach for creating a long object from user input, and why?

Thank!

0


source to share


2 answers


I would advise not to allow domain objects to go out of the domain level and into the presentation layer. Keep the presentation layer focused on the presentation.

For this reason, I create data transfer objects to shuffle data to and from the domain and view layers. In your case, fire up a DTO dialog that will be passed to your service and translated into the appropriate domain object.



However, you wouldn't want to build domain objects from DTOs. Consider the case where the DTO only represents a subset of the domain object . Re-constructing an existing domain object from such a DTO will give you a partial domain object. You probably want to keep a lightweight cache that stores the full domain object so you can update accordingly.

Basically, you would arrive at a DTO solution if you refactor the Inject Parameters Object .

+2


source


There are two main ways I would handle this

1) If this is a setting through a dialog, I would create classes that implement the command template and associate the dialog with the given object. For example, CmdCreateConfigurationService and CmdEditConfigurationService.

The CmdCreateConfigurationService will rely on the factory class and minimum parameters needed to select the correct configuration service.



You are configuring the IConfigurationServiceEditor interface and passing that as one of the parameters to the CmdEditConfiguration parameters. With the IConfigurationServiceEditor interface, you define as many methods as you need to make the transfer of information from and to the dialog as easy and painless as possible. I recommend using a set of keys and values. The command object knows how to configure the configuration service from this collection. The dialog knows what to expect for this collection when configuring.

Regardless of the data structure, you will be doing the job of populating the configuration service in the command object. Because the non dialog / form / screen object implements IConfigurationServiceEditor, you can automate your testing and simplify the configuration of complex objects in certain circumstances.

I developed this method for CAD / CAM software that has dozens of parametric shapes, each with 4 to 40 entries.

0


source







All Articles