True Object oriented approach in designing/developing applications is really important as it saves you from a hell of a maintenence nightmare if you are working on a medium to large scale project.
Classes , abstract classes and interfaces are the cornerstone of object oriented programming in .NET framework.And you must know , precisely in which situation you go for which one of the above.Now first start off with some definitions and then we’ll get our hands dirty with some nifty examples.
Abstract Class:
An abstract class may contain fields , properties , methods , events etc.But it doesn’t allow its consumers to instantiate its object.It rather provides some basic functionality that isn’t useful if you create its instance.However if some child class inherits it and extend its functionality to some meaningful extent then it becomes very helpful as it contains the basic logic already and child class only need to add its own flavour.You will notice that behaviour throughout in .NET framework. The .NET class library contains WebRequest and WebResponse abstract classes.But they are not very useful on their own.Instead HttpWebRequest and HttpWebResponse are the concrete classes that drive from WebRequest and WebResponse respecively are so much useful because they are specifically developed for some concrete protocols like Http. Similarly System.Drawing.Brush is another abstract class but LinearGradientBrush and SolidBrush are actual concrete classes.
Rule of thumb : Use abstract classes when you want to build some basic logic that cannot be used alone. Instead you want developers to extend their logic by building on top of your base class.
In the next post I will sum up interfaces and simple classes along with their appropriate scenarios in which they will be suitable.
Till then happy coding
