D
D
dmitriy2018-08-21 23:55:42
PHP
dmitriy, 2018-08-21 23:55:42

What to do if the class has a lot of dependencies?

I use an anemic model during development, respectively, Service, Repository and infrastructure dependencies Request, Configs, FormBuilders, Logger, etc. are actively used in constructors.
What to do if there are a lot of dependencies going through the constructor, more than 5 and sometimes 10 ?
ps Fortunately, Autowaring DI is involved in assembly and dependency injection, but still.

Answer the question

In order to leave comments, you need to log in

17 answer(s)
M
Mikhail Osher, 2018-08-22
@dmitriylanets

Facade pattern is a structural design pattern that allows you to hide the complexity of the system by reducing all possible external calls to a single object that delegates them to the corresponding objects of the system.

B
bkosun, 2018-08-22
@bkosun

Does your class actually have a hard dependency? If some of the dependencies are optional, maybe you should consider removing them from the constructor and using setters?
Is the Single Responsibility Principle respected?
https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B8%D...
https://en.wikipedia.org/wiki/Single_responsibilit...

A
Anton Shamanov, 2018-08-22
@SilenceOfWinter

1. Think about why it happened and, if possible, distinguish.
2. Do not forget that aesthetics is certainly good, but performance is more important to the client - the fathers, as they say in plain text, if you want a blog, don’t get angry - blindly, and if refactoring has already been invented.

D
Dmitry Afonchenko, 2018-08-22
@Indermove

Probably stupid advice, but the following usually helps me.
If I have, for example, a Repository and a Service, and my response from the repository is processed by the methods of the service, while the service is not used anywhere else, then
1) I create a new interface. For example FiltrationDataServiceInterface and pass it to the bloated constructor instead of these two classes.
2) In the implementation of the interface, I already use them for one method.
3) I use this method in the original class, the dependencies of which I wanted to reduce.
This way you can combine several services into one and reduce the number of dependencies in a bloated class.
I would not consider a logger as a dependency, since it is completely self-sufficient and, in essence, is not part of your logic. That is, if I have 4-5 dependencies, and at the same time one of them is a logger, then this is not very scary. But here, of course, the topic for holivar can unfold, therefore, this is just my opinion.

V
Vilintritenmert, 2018-08-30
@Vilintritenmert

The impression that the class has many responsibilities ... violation of Single Of Responsibility

M
makeey, 2018-08-22
@makeey

I recommend reading the book . And just as it was already said to read about SOLID. As for the "aesthetics", I do not agree, because in the future it will be difficult to maintain the code.

M
M1Anderson, 2015-02-12
@M1Anderson

Django will take you very far, just like any serious framework. In general, it's either ruby ​​or python. Both languages ​​are great.
And I would not advise you to get into PHP, because it is difficult to get out later.

O
OnYourLips, 2015-02-12
@OnYourLips

You're not right.
You do not need to cover a wide area and know several areas. You need to know only one, but be a professional in it.
I am very sorry that I did not choose it myself at the time.
PHP has a low minimum entry threshold, but becoming a middle is more difficult - it will take more time.

I
Ivan Velichko, 2015-02-19
@Ostrovski

Python or js. And PHP by no means as a starting language. It gives a too distorted understanding of the web development background due to the peculiarities of the interpreter (isolating the script environment, resetting the interpreter between requests). At the same time, Python, JS, Ruby, and most likely Java, although I have no experience with the latter, look very similar in terms of web development. General principles for building and running applications, multithreading, asynchrony (as a possibility). PHP has none of this, everything looks much more linear and simplified there. Switching from Python or Ruby to PHP (if necessary!) will be an elementary task, but the opposite is not true, there will be too many new concepts to master.
And no frameworks at the beginning of the training! A Django programmer sounds as bad as a jQuery programmer. It's like a brand. A programmer is, first of all, an understanding of the general principles of development, and only then languages, frameworks, etc. So, first of all, you need to deal with wsgi . Write a couple of your own scripts that process requests. Check out how this kitchen works . Then you can start using flask .
PS Add. pluses of Python, JS, etc. - the scope of their use is not limited to the web. Perhaps in the future you will be happy about this when you decide to program fighting robots instead of websites or try yourself in machine learning or somewhere else.

X
xtalen, 2015-02-19
@xom9lk

I was a logistician, I want to become a chef, which cuisine should I study?

T
tzlom, 2015-02-19
@tzlom

Well, you already understood that you can’t take PHP in any case, otherwise pythonists and rubists will be offended, but in general it is also an excellent language for the web (and the most common, both in terms of the number of installations and infrastructure, no matter what they say there).
In general, as I look at the step from a system administrator to a programmer, this is a big and difficult step, not everyone succeeds and not always like it, so the question is whether you had any serious programming background in general (yes, you are a system administrator and probably wrote scripts , but this is usually not what the programmer does, although it looks the same). If you haven’t been and you don’t understand how the web works (and this is to have a clear idea of ​​​​what it is and how it works together: nginx / apache, cgi , HTTP, browser, HTML , AJAX), then it might be worth starting not immediately with web development, but from programming in general.

B
beduin01, 2015-02-12
@beduin01

I generally started writing applications in D. For convenience, like Python. The language is compiled and strongly typed.
Read ddili.org/ders/d.en/index.html
If you like it, then proceed. The entry threshold is not higher than that of Python.

D
David Mzareulyan, 2015-02-17
@david_mz

Python is a very good choice. Even on the web without JavaScript, there is nowhere, at least you need to understand it approximately. And not only the language itself, but also the infrastructure around node.js - npm, grunt / gulp, etc.
Of the new languages, you can look at Go - many productive and near-system (the same docker) things are now being written on it, perhaps you , as a system administrator, it will seem interesting.

P
Pavel Vishin, 2015-02-19
@SadBubble

In my humble opinion, and contrary to the majority, I will risk being thrown by plmidors. Python or PHP, coupled with a popular framework, is what you need at the start. I will not write about the pros or cons of both languages, or any others, because the point is not that. Any more or less sane programmer will say that all languages ​​are, one way or another, good for their purposes. All solve certain problems. In the case of the author of the question, the task: to quickly join the world of software developers and quit their current job. To do this, he needs a language with which he will get a job as a programmer without much research, where he will already be taught by colleagues and real tasks. And a hypothetical study of hypothetical asynchrony in a hypothetical "ToDo list" project on node.js without actually applying knowledge to live tasks will be quickly forgotten. As a result, a person will never engage in commercial development. And there will be another hobby programmer.

M
Mikhail Potanin, 2015-02-19
@potan

If you feel strong in yourself - try Scala. The language is in demand in corporate and web (server) programming. It is quite applicable to android development. But complicated.
Of the simple but popular ones, it is better to take Coffeescript.
If you decide not to become a programmer, but to remain a system administrator - Perl.

V
Vasily minodvesP, 2015-02-20
@benoni

A python web developer can live not only with dzhanga. There's also Flask, Bottle.py, Cherry.py, Tornado, and a few others. ;)
Of the ones requested for the web: javascript with Node.js, PHP (of course, Wordpress, Joomla. Laravell, and other famous ones).
From the enterprise: Java, C#, which, in principle, can also be used for the web.
And of the simple ones (but, alas, not very popular): Lua (mainly for games, but also for the web and desktop, you can also write in Lua in principle) and Erlang. I know Erlang in 2 weeks, you can completely learn and write for production, Lua - I think it's easy to learn too (maybe it's even easier to learn python). Here is the current Erlang or Lua, it will probably be easier for a programmer to create his own startup than to find an employer in these languages.
and probably the most optimal in terms of the ratio of lightness, versatility and relevance - python and java script.

B
bxN5, 2016-06-23
@bxN5

here is a good article phpinfo.info/kakoj-yazyk-programmirovaniya-vybrat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question