Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is a <code>User</code>?</p> <p>I don't mean in the sense of where is the class defined, but in the sense of what does it physically mean in the domain? It sounds like you're trying to get it to mean multiple things.</p> <p>Instead of trying to fit these actions into a model for the domain, create action models for them. Something like this:</p> <pre><code>class CreateUserAction { public string Username {get; set;} } class DeleteUserAction { public int ID {get; set;} } </code></pre> <p>Then use these in your action methods:</p> <pre><code>public ActionResult Create(CreateUserAction user) { } public ActionResult Delete(DeleteUserAction user) { } </code></pre> <p>This will break out the different purposes into different classes, in accordance with the single responsibility principle. Now the <code>User</code> class can focus on simply representing a user object, as opposed to <em>sometimes</em> representing a not-yet-created user or <em>sometimes</em> representing only the ID of a user object, etc.</p> <p>One major benefit here is that you can specify the validation rules directly in the class. With this approach, a <code>User</code> object can <em>always</em> require a <code>Username</code> <em>and</em> an <code>ID</code> to be valid. Whereas a <code>CreateUserAction</code> object doesn't even have an <code>ID</code> (since it doesn't need one) and a <code>DeleteUserAction</code> object doesn't have a <code>Username</code> (since it doesn't need one).</p> <p>You can further add additional fields as needed. For example, the <code>CreateUserAction</code> object will likely have other fields to describe the user being created. (It may even have fields that don't go on a <code>User</code> object at all, but would be translated into some other object in the domain.) However, the <code>DeleteUserAction</code> may never need anything more than an <code>ID</code> (and, as suggested by SLaks, can probably be replaced with just an <code>int</code> for that action method, but that's up to you).</p> <p>Clearer roles and responsibilities for classes, fewer partially-initialized half-objects.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload