Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You first need to layout your domain model. here's small example how it could be (warning sample code, just to show the principle)</p> <pre><code>public abstract class BaseSpell { public string Name { get; set; } //... all spell related stuff public abstract int CalculateDamage(BaseCharacter character); } public class FireballSpell : BaseSpell { public override int CalculateDamage(BaseCharacter character) { //return the number of damagepoints if (character is WizardCharacter) return 0; if (character is BarbarianCharacter) return 100; } } public abstract class BaseCharacter { public int HitPoints { get; set; } public int XP { get; set; } public int Mana { get; set; } public string DieQuote { get; set; } // add all character related properties // implemented by child classes public abstract void UnderSpell(BaseSpell spell); public abstract void UnderDamage(int damage); public abstract void Die(); //... } public class WizardCharacter : BaseCharacter { // implement wizard public override void UnderSpell(BaseSpell spell) { // wizards are immune to spells UnderDamage(spell.CalculateDamage(this)); } public override void UnderDamage(int damage) { HitPoints -= damage; if (HitPoints &lt;= 0) Die(); } public override void Die() { // do whatever necessary DieQuote = "All your base are belong to us!!!"; } } public class BarbarianCharacter : BaseCharacter { public override void UnderSpell(BaseSpell spell) { // barbarians are susceptible to spells UnderDamage(spell.CalculateDamage(this)); } public override void UnderDamage(int damage) { HitPoints -= damage; if (HitPoints &lt;= 0) Die(); } public override void Die() { // do whatever necessary DieQuote = "I'll be back baby!"; } } </code></pre> <p>Then you need to create a service layer that interacts with the different entities in the domain (characters, spells, ...) and presentation layer that extracts the data needed for representation on your webpage. For example you could have a partial view where your show the status of your character (hitpoints, mana, XP,...) This is where the Viewmodel comes into play:</p> <pre><code>// presenter public class CharacterPresenter { public CharacterViewModel MainCharacterViewModel(){ // fill model with main character data (ie Character class) } } // controller public class CharacterController : Controller { private readonly CharacterPresenter characterPresenter; public CharacterController () { characterPresenter = new CharacterPresenter; } public ActionResult Info() { var model = characterPresenter.MainCharacterViewModel(); return View(model); } // and so on... } </code></pre> <p>Viewmodels are used to convey data between your controller and service layer. Typically they don't expose behaviour, that's what domain models are for...</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