Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to have separate service classes for each business layer. And trying another possibility with partial classes. Please suggest which one is better one.

regards, anand

Option 1:

   [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);
    }

    [ServiceContract]
    public interface IService2
    {
        [OperationContract]
        string GetData2(int value);
    }

    [ServiceContract]
    public interface IService3
    {
        [OperationContract]
        string GetData3(int value);
    }

        public partial class Service1 : IService1
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }
}

public partial class Service1 : IService2
{
    public string GetData2(int value)
    {
        return string.Format("You entered: {0}", value);
    }

}

public partial class Service1 : IService3
{
    public string GetData3(int value)
    {
        return string.Format("You entered: {0}", value);
    }

}

Option 2:

enter image description here

share|improve this question

migrated from stackoverflow.com Mar 12 '12 at 13:27

This question came from our site for professional and enthusiast programmers.

1  
Is the goal of the first one only to achieve separation in the source files? – Joshua Drake Mar 30 '12 at 17:03

It depends what you are trying to achieve? I'm unsure from your initial question.

If you use partial classes, based on your example; you will have 1 class (Service1) which implements 3 interfaces (IService1, IService2 and IService3).

If you want a single class which implements 3 interfaces but the implementation details for each interface are kept separate then partial classes will work.

share|improve this answer
    
The only "problem" here is that with using partial classes you actually don't split anything. It's just one huge class. You can do it. If you want to improve readability it might be a good idea. But imo in terms of good code you should use a more dynmaic apporach. Anways both ways will work. – basti Jul 11 '12 at 6:27

Have you tried looking into Request/Response pattern using Dependency Injection? It's a bit complicated to setup, but for large services, it's quite a flexible and scalable pattern.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.