Tuesday, July 10, 2012



Abstract class

We all know one thing for sure about abstract class and that is it cannot be instantiated, 

So whats the point in creating a class for which objects cannot be created? hold on a sec, you can still inherit the abstract class and define the abstract methods in it and then create objects for this class, so there you are successfully implemented the 'cant-be-instantiated-class'.
now think of an example one is clay,

And no doubt its a must that the abstract class must be inherited, otherwise the point of creating the abstract class goes void..

Interfaces

interfaces have many things in common with abstract classes, so lets see what makes them different, in interfaces you just give a skeleton of functions that has to be used in the classes that implements it..all methods are abstract in interfaces but not the case in abstract class, 
and doing so you cannot specify any access modifiers for the functions, and the a single class can implement many interfaces unlike abstract classes is inherited by only one class…

So the question is, what to use where??

lets take the example of a set of[ audio+video+text+drawings] they come under -> information..


                                       Information
                                         Post_it()

         Audio                                                   Images
                             video              Text

       


now information can be normal class | interface | abstract class

can't be class as its not got any functions to implement nor any objects to create.
if i choose it to be interface then, any changes to the interface then all the implementing classes must be modified.
incase you choose it to be a abstract class, and any method you include later on can even be concrete and so no updations in all the implementing classes is required, and no multiple inheritance can be supported..



Partial class..

Partial itself hints you that a single class is split into 2 for easier developing, let me explain with an example

Say: You are about to create an application and you have 2 developers working on different aspects of a specific thing…
in that case you can very well split the class between the 2, and while compiling the compiler merges the partial classes into 1.