Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The point is that the interface represents a <em>contract</em>. A set of public methods any implementing class has to have. Technically, the interface only governs syntax, i.e. what methods are there, what arguments they get and what they return. Usually they encapsulate semantics as well, although that only by documentation.</p> <p>You can then have different implementations of an interface and swap them out at will. In your example, since every pizza instance is an <code>IPizza</code> you can use <code>IPizza</code> wherever you handle an instance of an unknown pizza type. Any instance whose type inherits from <code>IPizza</code> is guaranteed to be orderable, as it has an <code>Order()</code> method.</p> <p>Python is not statically-typed, therefore types are kept and looked up at runtime. So you can try calling an <code>Order()</code> method on any object. The runtime is happy as long as the object has such a method and probably just shrugs and says »Meh.« if it doesn't. Not so in C#. The compiler is responsible for making the correct calls and if it just has some random <code>object</code> the compiler doesn't know yet whether the instance during runtime will have that method. From the compiler's point of view it's invalid since it cannot verify it. (You can do such things with reflection or the <code>dynamic</code> keyword, but that's going a bit far right now, I guess.)</p> <p>Also note that an interface in the usual sense does not necessarily have to be a C# <code>interface</code>, it could be an abstract class as well or even a normal class (which can come in handy if all subclasses need to share some common code – in most cases, however, <code>interface</code> suffices).</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