Friday, November 14, 2014

C# Virtual vs Abstract

MVC with Entity Framework is forcing us to revisit some details of the C# language that seemed obscure or esoteric at the time we learned them.

LINQ famously did the same (with stuff that only came with # 2.0), with Generics, Delegates, Anonymous Methods, Enumerators and Yield,
(and from C# 3.0, as if created only for the purpose of later usage with LINQ) Local Type Inference, Lambda Expressions, Extension Methods, Object Initialization Expressions, Anonymous Types, and Query Expressions.

An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class.

A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality.

TODO:
Describe difference between virtual function as opposed to virtual properties.

NB: This post inherited from http://stackoverflow.com/questions/391483/what-is-the-difference-between-an-abstract-function-and-a-virtual-function

No comments: