Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Attributes or variables are often "base" types of a language. The question is what you can sensibly abstract.</p> <p>For example, you can reduce a <code>Wheel</code> to descriptors made up of base types like integers, floating-point values and strings, which represent characteristic attributes of any wheel: <code>numberOfTreads</code>, <code>diameter</code>, <code>width</code>, <code>recommendedPressure</code>, <code>brand</code>. Those attributes can all be expressed with base types to make a <code>Wheel</code> object.</p> <p>Can you group some of those attributes into a more abstract arrangement that you can reuse, independent of a <code>Wheel</code>? I think so. Perhaps create a <code>Dimensions</code> object with the attributes <code>diameter</code> and <code>width</code>. Then your <code>Wheel</code> has a <code>Dimensions</code> object instance associated with it, instead of <code>diameter</code> and <code>width</code>. But you could think about using that <code>Dimensions</code> object with other objects, which may not necessarily be <code>Wheel</code> instances.</p> <p>Going up the list, you can reduce a <code>Car</code> to be made up of base types, but also other objects, such as <code>Wheel</code> objects. It is sensible to do so, because other motor and non-motor vehicles (such as a <code>Bicycle</code>) also contain <code>Wheel</code> instances.</p> <p>Abstracting <code>Wheel</code> and <code>Dimensions</code> lets you re-use these object types in different contexts you may not initially consider. It makes your life a little easier because you have less code to rewrite, in theory.</p> <p>If you can create a hierarchy of objects, to the point where the deepest, lowest-level object is only made up of a few base types, that is probably a good place to start. </p>
 

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