Non-virtual interface pattern: Difference between revisions

Content deleted Content added
Rewrote the C# Example of the pattern to something much more readily accessible.
Improved the C# Example and added comments.
Line 35:
public abstract class Saveable
{
// The invariant processing for the method is defined in the non virtual interface.
// The behaviour so defined is inherited by all derived classes.
public void Save()
{
Console.WriteLine("Creating transaction");
CoreSave();
Console.WriteLine("Committing transaction");
}
// Variant processing for the method is defined in the subclass interface.
// This behaviour can be customised as needed by subclasses.
protected abstract void CoreSave();
}
Line 54 ⟶ 60:
}
}
</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 ==