Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you should really do is <a href="http://sites.google.com/site/michaelsafyan/coding/design/coding-best-practices/design-from-the-top-down-not-bottom-up" rel="nofollow noreferrer">code from the top-down, not from the bottom-up</a>. Write your main function as clearly and concisely as you can using APIs that you have not yet created as if they already existed. Then, you can implement those APIs in similar fashion, until you have functions that are only a few lines long. If you code from the bottom-up, you will likely create a whole lot of stuff that you don't actually need.</p> <p>In terms of when to create an interface... pretty much everything should be an interface. When you use APIs that don't yet exist, assume that every concrete class is an implementation of some interface, and use a declared type that is indicative of that interface. Your inheritance should be done solely with interfaces. Only create concrete classes at the very bottom when you are providing an implementation. I would suggest avoiding abstract classes and just using delegation, although abstract classes are also reasonable when two different implementations differ only slightly and have several functions that have a common implementation. For example, if your interface allows one to iterate over elements and also provides a sum function, the sum function is a trivial to implement in terms of the iteration function, so that would be a reasonable use of an abstract class. An alternative would be to use the decorator pattern in that case.</p> <p>You might also find the Google Techtalk "<a href="http://www.youtube.com/watch?v=aAb7hSCtvGw" rel="nofollow noreferrer">How to Design a Good API and Why it Matters</a>" to be helpful in this regard. You might also be interested in reading some of my own <a href="http://sites.google.com/site/michaelsafyan/coding/design" rel="nofollow noreferrer">software design observations</a>.</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