What is the difference between 'Interface' & 'Abstract Base Class' ?


Hi,

Good day. Can you please explain what do you mean by 'Interface' and 'Abstract Base Class' and what are the differences between those two ?.

Advance ThanX for your time & patience.

Bye...
kishore

Comments

  • :
    : Hi,
    :
    : Good day. Can you please explain what do you mean by 'Interface' and 'Abstract Base Class' and what are the differences between those two ?.
    :
    : Advance ThanX for your time & patience.
    :
    : Bye...
    : kishore
    :

    An interface is a pretty broad description, it simply is a means (such as a function or group of functions) that give access to an object. Commonly interfaces allow access to private data or routines stored in objects. A interface could be as small as a single function on an object, or as large as a complex inferface such as the Windows API that has hundreds of functions to allow access to the windows OS.

    An "Abstract Class" is class the cannot be instantiated. A "Base Class" is the parent class (highest class) in a class hierarchy. This lends on the idea of inheritance. A child class can inherit data members and functions from a parent class. If the parent class is "Abstract" it means you can only access it's data members and functions through an instance of a child class. For example, if you have an Abstract Base Class "Vehicle" and two sub(0r child ) classes "Car" and "Truck". You cannot create an instance of Vehicle you would have to create an instance of Car or Truck.

    Hope that helps all these concepts can be explored further in any book that covers OOP (Object Oriented Programming).

    ~rlc


  • An interface will define ONLY the required function signatures that an object will guarantee to be available. There will be NO implementation details. This is the same as saying "a computer has a keyboard." The implementation is the form of that keyboard (MS ergonomic, standard, dvorak, etc.). Generally if you know that you will have a keyboard you have an idea of what to expect. Same for an interface. This supports polymorphism because any variable declared as type InterfaceXYZ can point to ANY object instance that implements that interface. It's like saying:

    Dim X as IDataBase
    X = New SQLDatabseObject()
    X.DoWhateverFunctionDefinedByIDataBase()
    X = New OracleDataBase()
    X.DoWhateverFunctionDefinedByIDataBase()

    Here X doesn't know if it is pointing to SQL, Oracle, or some other object that implements IDataBase and furthermore, it doesn't want to know. X can call any function that is defined by IDatabase. If wanted to use extra functionality defined by the class SQLDatabaseObject you would have to cast X to Type SQLDataBaseObject but you would NOT be able to point X at an OracleDatabaseObject.

    Now, suppose you have a situation where the whole family of objects that share this interface should ALSO share some functionality. Why write the same code in EVERY subclass? You CAN'T do this with an interface implementation. You must write a class that contains the shared functionality and inherit it. Then any functions that you want to GUARANTEE that the whole family exposes (like in an interface) you would just write a MustOverride/abstract function. If you want default behavior that the inheriting class can optionally change, you would write an Overrideable/virtual function.

    Hope this helps.

    -ray
  • //[link=http://www.cegonsoft.com/jobassistanceprogram.php]Abstarct[/link] Class

    public abstract class Vehicles

    {

    private int noOfWheel;

    private string color;

    public abstract string Engine

    {

    get;

    set;

    }

    public abstract void Accelerator();

    }

    //Interface

    public interface Vehicles

    {

    string Engine

    {

    get;

    set;

    }

    void Accelerator();

    }

    More Details : [link=http://www.aboutcegonsoft.com/]Abstract & Interface[/link]
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories