Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
We use interfaces in our application but what is the correct way to add them in our application?
Shall we create an interface first and declare all the functions needed in a class Or Shall we define all our functions inside the class and then declare them in the interface?Whats the correct way?
Posted
Comments
phil.o 5-Dec-13 13:24pm    
And what difference do you think it makes? Normally sanity would be to define the interface and then implement it in a concrete class, but nothing prevents you from doing the contrary; as long as interfaces and their implementation are here at compile time.

1 solution

There is no right way to do this. Its a Chicken and Egg problem, either you start with the chicken (class) or the egg (interface).

Personally I start with the interface then write one concrete class and adjust the interface as needed. Then once I get the functionality down, I can write the other concrete classes.

Just keep in mind, don't create interfaces for the sake of creating interfaces. Only create interfaces when you need to define a contract for other concrete classes to implement.

You can also create interfaces (at least in VS Standard or above, not sure about express) by right clicking on a class and selecting Refactor>Extract Interface.
 
Share this answer
 

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