Content deleted Content added
Added a C# example of the pattern. |
→C# example: add image |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 31:
}}</ref>
<syntaxhighlight lang="c#" line="1">
public abstract class Saveable
{
public class Node<TData>▼
// The behaviour so defined is inherited by all derived classes.
// For example, creating and committing a transaction.
{
Console.WriteLine("Creating transaction");
public TData Data { get; set; }▼
public Node<TData> Next { get; set; }▼
Console.WriteLine("Committing transaction");
▲ {
public override string ToString()▼
}
// This behaviour can be customised as needed by subclasses.
// For example the specific implementation of saving data to the database.
protected abstract void CoreSave();
}
public class Customer : Saveable
{
{
Console.WriteLine($"Saved customer {Name} with credit limit {Credit}");
▲ // Non virtual interface pattern
▲ // The invariant processing necessary for the API is implemented in our `public` methods.
▲ // The variant processing necessary to implement the API in a doubly linked list.
}
}
</syntaxhighlight><ref>{{Cite web|title=Non-Virtual Interface Design Pattern|url=http://www.blackwasp.co.uk/nvi.aspx|access-date=2021-09-19|website=www.blackwasp.co.uk}}</ref><ref>{{Cite web|title=Non-Virtual Interface Design Pattern (Page 2 of 2)|url=http://www.blackwasp.co.uk/nvi_2.aspx|access-date=2021-09-19|website=www.blackwasp.co.uk}}</ref>
== See also ==
|