Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Alot going on here and I wonder if this is homework because of the "IFoo", or maybe you made that replacement to simplify the example.</p> <p>-<code>: ServiceHostFactory</code>, HostFactory inherits from ServiceHostFactory.</p> <p>-<code>HostFactory&lt;TApp&gt;</code>, HostFactory is a generic type as it has a type parameter of TApp. Whenever someone uses the HostFactory class, they can specify a type for TApp which will cause that type to be used everywhere TApp appears int he code. So if the class has a function <code>TApp GetApp()</code> and they specify <code>&lt;int&gt;</code> for TApp, then GetApp is actually <code>int GetApp()</code></p> <p>-<code>where TApp : IFoo</code>, TApp must implement the IFoo interface(this could have been a class as well, indicating it must inherit from that class, not necesarily directly).</p> <p>-<code>abstract</code>, HostFactory is an abstract class, meaning other classes can inherit from it, but no code can instantiate the HostFactory itself. This would be like me giving you the frame of a car, and saying, you're not legally allowed to drive this on the road, but you're welcome to make a car of your own out of it.</p> <p>-<code>public</code> HostFactory is public, meaning it is visible to code outside of the assembly in which it was declared.</p> <p><strong>Edit: More on generics</strong> I will start with a pretty significant quote from <a href="http://msdn.microsoft.com/en-us/library/ms379564%28VS.80%29.aspx" rel="nofollow noreferrer">MSDN</a>: "Generics are the most powerful feature of C# 2.0."</p> <p>You would use generics when you write something that could conceivably work with many types. For example, before we had generics in 2.0, we had to cast everything to an Object before we could place it in a collection, which was really dangerous because the copmpiler couldn't verify that you were casting to the correct type whenever you later got an item out of the collection. With generics we can do <code>ArrayList&lt;bool&gt;</code> to create an ArrayList of bool's and now there is no need to cast. The compiler can verify that we are putting bool's into the collection.</p> <p>For example, in the above class we can write algorithms that work with things that implement IFoo, knowing only that the object will be able to do things that an IFoo interface has. So I can write an algorithm that calls methods on the IFoo interface, and then my algorithm can be reused in the future by anyone who implements the IFoo interface.</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