- Home /
Working with interfaces, best practices?
Hi all,
I plan to start developing a new project and i want to use interfaces, however i am new to them. How should i implement them in a tidy manner.
Should each interface have its own IMyInterface.cs? Should i put interfaces that have similar effects to the same IMovementStuff.cs (e.g blinkable, dashable)? Should i avoid implementing too many interfaces in one class? Can i future proof them somehow so i can edit them in the future or have other interfaces built on the functionality of my basic ones. ( e.g have a doubledashable interface work after the dashable interface?
I dont expect answers in all my questions, i wanted to give a general idea of what i am asking.
Answer by Landern · Feb 27, 2015 at 01:35 PM
This is kind of all over the place and subjective. It's been my experience to separate our your interfaces into logical folders, most likely into a ~Interfaces folder. Put each into it's own ISomeInterfaceName.cs file. You may even want to add a namespace, "namespace MyGame.Types.Interfaces" to scope things.
But this is a design question and really can go any number of places, this isn't really the place for a back and forth discussion, that is what the forums are for.
I would also look at FuzzBuzz, you probably don't need to go nuts over the interface pattern and this will show you why(lord i hope so): https://github.com/EnterpriseQualityCoding
Small question, the reason that it is good to add a namespace is because
two interfaces could have a same variable or same function name? so there are no mixups?