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?
2 answers
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
|
Single Responsibility- Bulson