V
V
Vladislav2021-04-15 08:55:09
Software design
Vladislav, 2021-04-15 08:55:09

Why is Segregation of Responsibility important?

Hello!

The explanation of "Why is SoC so important?" SoC , specifically

Keeping different responsibilities together in a single class, you have to maintain their consistency simultaneously in every operation within this class. That quickly leads to a combinatorial explosion.


1. consistency - in the sense of compliance (the code must correspond to the behavior that is required, the absence of bugs) within all operations?
2. What does it mean
a huge amount of combinations in which elements of these concerns can interact with each other.
?
2. We need an example illustrating paragraphs. 1, 2. If possible, a real example.

I thought on the example of Eloquent .

If we imagine that everything will be in one class, for example, Model, by combining all the methods and fields, can we make a mistake?
Is it just because of the great complexity associated with the fact that now for many methods there is no obvious context in the form of a class, and it is now difficult to find anything in 15,000 lines of code? Having broken everything into methods, DRY all subject knowledge, then there will be no problem of invariant violation (except because it is easy to get confused and introduce the possibility of invariant violation into the code)?
But if it is still bad to choose the method boundaries of almost all methods, then the code will become confusing garbage, and will no longer reflect the semantics of the domain. I was not able to come up with this code so that there were no duplications of the subject logic, because you need to break methods that are used multiple times. An example if you change the scope of a method and all called methods inside it: Builder::eagerLoadRelation .

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cicatrix, 2021-04-15
@vs101ff

Abstract if, pseudocode

password = Window.TextBoxPassword.Value
if (!password.RegexMatch('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#[email protected]$ %^&*-]).{8,}$"))
     Window.ValidationText.Text = "Пароль слишком слабый";
else
     try
         connection = new Connection("connecttion string to database");
         .RunSQL("update users set password = @password where username = @user"
     catch  
         Window.ResultMessage.Text = "Ошибка"
Window.ResultMessage.Text = "Пароль изменён"

And there are 3 such pieces in the program, for example, where the password changes, but you only know about 2, since the third one was added without you.
Questions: What happens if password requirements change?
What happens if the window design or the UI framework in general changes?
What will happen if the database engine, table names change?
compare c:
password = GetUserInput();
if (ValidatePassword())
{
    UpdateUserPassword()
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question