Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several reasons for the different approaches. Consider the following:</p> <pre><code>public abstract class MyAbstractBaseClass { String m_url; public MyAbstractClass(String url) { m_url = url; } public abstract String GetSiteData(); } public class SiteAGetter : MyAbstractBaseClass { // ... public override String GetSiteData() { // ... } } </code></pre> <p>With this abstract method, you are forced by the compiler to really implement the GetSiteData() method in every overriding implementation. You could, of course, just implement the GetSiteData in the base class as</p> <pre><code>public virtual String GetSiteData() { return null; } </code></pre> <p>But now you don't <em>need</em> to implement the method in derived classes and you would need to make sure at every place where you call the method that the return value is non-null before you use it. So basically it is a help to yourself to prevent any obvious errors (you do not want anyone to write a derived class which does not implement that method). Also, an abstract class cannot directly be instantiated, so no one will make the mistake of creating an instance of the base class, because the compiler prevents it.</p> <p>Interfaces serve a slightly different purpose: They can be implemented by different, unrelated classes. So if for some reason you cannot create a common base, but you want several classes to expose the same interface (= to offer the same functionality) but they are not related, use an interface. Interfaces are also used for other reasons, such as Mocking in unit test environments. There's even more to this, I suggest you read some good book about it and then ask more specific questions. </p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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