Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>So what steps are best used to go from English (or whatever your language is) to computer code?</p> </blockquote> <p>Experience is what teaches you how to do this. If it's not coming naturally yet (and don't feel bad if it doesn't, because it takes a long time!), there are some questions you can ask yourself:</p> <ul> <li><p>What are the main concepts of the system? How are they related to each other? If I was describing this to someone else, what words and phrases would I use? These thoughts will help you decide what classes are useful to think about.</p></li> <li><p>What sorts of behaviors do these things have? Are there natural dependencies between them? (For example, a <code>LineItem</code> isn't relevant or meaningful without the context of an <code>Order</code>, nor is an <code>Engine</code> much use without a <code>Car</code>.) How do the behaviors affect the state of the other objects? Do they communicate with each other, and if so, in what way? These thoughts will help you develop the public interfaces of your classes.</p></li> </ul> <p>That's just the tip of the iceberg, of course. For more about this thought process in general, see Eric Evans's excellent book, <strong><a href="http://domaindrivendesign.org/books/evans_2003" rel="nofollow noreferrer">Domain-Driven Design</a></strong>.</p> <blockquote> <p>How do you decide where and when to create an interface, or use an abstract class?</p> </blockquote> <p>There's no hard and fast prescriptions; again, experience is the best guide here. That said, there's certainly some rules of thumb you can follow:</p> <ul> <li><p>If several unrelated or significantly different object types all provide the same kind of functionality, use an interface. For example, if the <code>Steerable</code> interface has a <code>Steer(Vector bearing)</code> method, there may be lots of different things that can be steered: <code>Boat</code>s, <code>Airplane</code>s, <code>CargoShip</code>s, <code>Car</code>s, et cetera. These are completely unrelated things. But they all share the common interface of being able to be steered.</p></li> <li><p>In general, try to favor an interface instead of an abstract base class. This way you can define a single implementation which implements N interfaces. In the case of Java, you can only have one abstract base class, so you're locked into a particular inheritance hierarchy once you say that a class inherits from another one.</p></li> <li><p>Whenever you don't need implementation from a base class, definitely favor an interface over an abstract base class. This would also be handy if you're operating in a language where inheritance doesn't apply. For example, in C#, you can't have a <code>struct</code> inherit from a base class.</p></li> </ul>
    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