You must Sign In to post a response.
  • Category: .NET

    Realtime scenario of Interfaces

    Hi Team,

    I have a little confusion regarding Interfaces in C#.
    I know what Interfaces is , how to implement it. But still I am unable to find myself where interfaces comes into picture in the programming. I doesn't know where and when to use interfaces when the requirement comes.

    Kindly explain me with some best example.

    Venkata Rajesh M
  • #767023
    Suppose when you are using .ashx handler and in that page you want to use Session the ashx handler will not have the Session class so what we need to is we have to inherit IReadonlySessionstate go through the below url...


  • #767024
    I hope you know the clearly about the INTERFACE. First I will explain with one real example.
    Let us consider we are going to form a "ZOO". we are going to bring "Animals".
    So we are going to create "Tiger" class. In the Tiger class we are going to specify all the habits ex. Eating habit, Walking hapit, Running Habit.
    So we are going to create "Lion" class. In the Lion class we are going to specify all the habits ex. Eating habit, Walking hapit, Running Habit and going to create more animalis like this.
    Here we can use INTERFACE. We should not miss the Eating habit, Walking habit, Running Habit of each animal's. and also we need the consistency in the naming of the habits.
    So we can have one interface "IHABIT" it has the methods Eating habit, Walking habit, Running Habit. But it will be vary for different animals. Now while creating the any animal class we have to use that interface. So that the Interface force us to implement the habits.

    This will help us not to miss any habits
    This will help us to maintain the consistency of the habits

    By Nathan
    Direction is important than speed

  • #767025
    Thank you SriRama and Nathan. Your explanations cleared my confusion to some extent.
    Would you please help me how these interfaces are helpful in plug and play architecture ?

    Venkata Rajesh M

  • #767036
    We know 'Plug-and-Play' approach allows us to experiment with alternative design choices of component interactions in plug-and-play manner, So YES interfaces are very much used in this approach.

    Now According to this source code:

    Once we have a class that implements defined interface, it can be "plugged" into the host application by dropping the containing dll into a specified folder, which provides the host application with a "pluggable" implementation of the exposed interface. so please take a look at this source code at once.

  • Sign In to post your comments