In my project there is a WCF service, there is an interface describing ServiceContract (IMainHost), and there is a class based on this interface (MainHost). And everything works fine. Only one thing confuses - a class of such size that the studio slows down when I edit it. Create another service so-so option. I can of course make it partial, but what if there are any other options?

  • 3
    So big, what even the Studio slows down ? Does it have to be thousands of 20 lines? - VladD
  • @VladD, there is no 3k lines, but when you enter the code, IntelliSense loads percent to 100% which creates a noticeable delay, well, and the resharper may still be undermined - Ivan K
  • one
    "... 3k lines ..." :) it seems someone forgot about the principle of Single Responsibility - Bulson
  • @Bulson, this principle just does not give me peace, I have analyzed this class many times for the sole responsibility, and came to the conclusion that it has one responsibility, this is the class of interaction between the chat and the server. In addition, the allocation of different areas of responsibility within the chat functionality, leads to the fact that you need to create several services, which draws the opening of several ports and so on ... - Ivan K
  • one
    At the moment you see your classroom as a monolithic wall, your task is to see this wall in such a way that the bricks from which it is made can be seen. - Bulson

2 answers 2

Delegation is the main design pattern in which an object outwardly expresses some behavior, but in reality transfers responsibility for the execution of this behavior to a related object.

Part of the internal implementation of MainHost to make sense of the individual classes and use them inside MainHost.

  • A good option, you probably should think about it and put it into separate classes, although I have a lot of different actions already made into separate classes, such as queries to the database, callbacks, various helpers, will it not lead to the creation of "spaghetti code" ? - Ivan K
  • It already depends on your implementation. - Artem Nikolayevich
  • @ ИванК Start writing unit tests to your “god-class”. Some of the methods will have to be made public. Through this, you will understand how you can break into associated classes. Then there will be a trace. stage - the creation of such classes and rewriting already under them tests. Working through tests, you can achieve your goal and be confident in the result. - Bulson
  • @Bulson, this is an implementation of the interface - there are all public methods, most likely. - Qwertiy
  • @Qwertiy do not frighten me like that :) You absolutely imagine a terrible situation - a class in which methods occupy 200 or more lines of code. Yet I hope for the best, i.e. methods that implement the interface call private methods that have reasonable functionality and size. - Bulson

Methods wcf-service should be a few lines:

 [АтрибутДляКонтроляПравДоступа(какие, то, параметры)] public Метод(Его аргументы) { return КакойТоBll.Метод(аргументы); } 

Total 6 lines (one blank) per method. The rest should be decomposed into bll-classes.

  • Thank you for the tips, I think I’ll do something like this, sorry I can’t mark 2 answers as correct - Ivan K
  • This option seems to me too complicated ... - Pavel Mayorov
  • @PavelMayorov, and in more detail? - Qwertiy
  • @Qwertiy return КакойТоBll.Метод(аргументы); - extra line - Pavel Mayorov
  • @Qwertiy and the public Метод(Его аргументы) - too - Pavel Mayorov