Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a real world example of an interface which contains a function returning an object of the same interface


Sample Code

public interface IProduct
{
    IProduct Products(string str);
}

public class Test : IProduct
{
    public IProduct Products(string str)
    {
        throw new NotImplementedException();
    }
}


What I have tried:

I tried googling. Did not get much answeer.
Posted
Updated 26-May-21 10:36am

Perhaps a search function might?
If the Interface was "media objects", then a static collection of all TV, audio, and movies, and a search function to return the Program / song / movie with a given name?
 
Share this answer
 
Anything that's heriarchical might do this, so say you have a tree structure of categories (or a tree structure of anything) then you might have a method to get an item's parent;

C#
public interface ICategory
{
    string Name { get; set; }
    IEnumerable<ICategory> SubCategories { get; set; }
    ICategory Parent { get; set; }
}
 
Share this answer
 
Comments
vaibhav1800 27-May-21 3:55am    
This looks great. Can I have a small example to understand the real life implementation ? Any link out there might help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900