Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I <em>just</em> read about this topic in <em><a href="http://www.manning.com/black2/" rel="noreferrer">The Well-Grounded Rubyist</a></em> (great book, by the way). The author does a better job of explaining than I would so I'll quote him:</p> <hr> <p>No single rule or formula always results in the right design. But it’s useful to keep a couple of considerations in mind when you’re making class-versus-module decisions: </p> <ul> <li><p><em>Modules don’t have instances.</em> It follows that entities or things are generally best modeled in classes, and characteristics or properties of entities or things are best encapsulated in modules. Correspondingly, as noted in section 4.1.1, class names tend to be nouns, whereas module names are often adjectives (Stack versus Stacklike). </p></li> <li><p><em>A class can have only one superclass, but it can mix in as many modules as it wants.</em> If you’re using inheritance, give priority to creating a sensible superclass/subclass relationship. Don’t use up a class’s one and only superclass relationship to endow the class with what might turn out to be just one of several sets of characteristics.</p></li> </ul> <p>Summing up these rules in one example, here is what you should not do:</p> <pre><code>module Vehicle ... class SelfPropelling ... class Truck &lt; SelfPropelling include Vehicle ... </code></pre> <p>Rather, you should do this: </p> <pre><code>module SelfPropelling ... class Vehicle include SelfPropelling ... class Truck &lt; Vehicle ... </code></pre> <p>The second version models the entities and properties much more neatly. Truck descends from Vehicle (which makes sense), whereas SelfPropelling is a characteristic of vehicles (at least, all those we care about in this model of the world)—a characteristic that is passed on to trucks by virtue of Truck being a descendant, or specialized form, of Vehicle. </p>
    singulars
    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