I've start using following method grouping to make my code more readable:
public interface IUserMethodGroup
{
void SomeMethodOne();
String SomeMethodTwo();
}
//File MainClass.Users.cs
public partial class MainClass : IUserMethodGroup
{
void IUserMethodGroup.SomeMethodOne(){ //some code }
String IUserMethodGroup.SomeMethodTwo(){ return "some str";}
}
//File MainClass.cs
public partial class MainClass
{
//HOW ABOUT PERFORMANCE?
public IUserMethodGroup UserHandle {get { return this; } }
}
Does it has big impact on performance?
Edit 1
This allow me to do that:
class ConsumerClass
{
public void Method()
{
MainClass mc = new MainClass();
mc.UserHandle.SomeMethodOne();
//@ vc 74:
//Interface has to be explicitly, otherwise it will be:
ms.SomeMethodOne(); //grouping lost...
}
}
@adelphus: Consider I have 5 similar properties (method groups). Every time I want to use some method from group I asking class to return itself. Does it be much slower compared to implementing without groups?
Every time I want to use some method from group I asking class to return itself. Does it be much slower compared to implementing without groups?
No. Returning this
in a read-only property should just be one line of IL code. In fact is may even be inlined by the JIT optimizer.
The bigger question is why do you have so many methods on one class? Having so many methods that they need to be "organized" by explicit interface implementations smells like you have a class that is doing too much.
One thing this design does allow is for you to have different classes that implement the different "groups". Your single class then becomes an aggregator that combines the functionality of several different interfaces into a single class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With