This could be a further question for the Workplace than technical. Whenever it involves convincing management we may come across several barriers that go beyond the code or system itself.
Imagining that we will not have these barriers, say, policies within your company that can prevent this, and that the company could allow a more "abrupt" change in a new project or existing project (besides OO, it could be a new language, framework, etc), that your colleagues are also aligned with your thinking, then we can go to the main point of this discussion.
I will try to argue in a less technical way, because you need to align your speech according to your interlocutor. If he argues very technically, he may not understand.
And, finally, I won’t get into the merits of whether or not it’s better than very common procedural approaches like Transaction Script.
The difficulty of putting it into practice
Although the subject of object orientation is always in the "mouth of the people", experience shows that it is not simple to implement it in practice.
If you look at the subject reference books, you will often come across very simple examples, or ones that start from questionable premises (example: using a bank entity as an object) or complex ones (DDD in general).
That is, when we are thinking only of the organization of objects to meet a problem, everything looks beautiful: I create an object Ordem
, who receives a Pagamento
, that can be done with Cartao
, etc..
But when we start talking about Apis entering data, saving information in the bank, validations, transactions, integrations, queues, retentatives, etc., things start to get very challenging and other approaches become more seductive. And this is what we didn’t even get to the challenge of composing the objects correctly (I get there).
So the ideal is to start with a problem simple and isolated. This would be the ideal scenario to propose this to your boss. Preferably, it could be embedded in a new system separate from the others. It is inevitable that there will be a huge learning curve if you haven’t worked professionally with object orientation yet, so this would be a good space to make mistakes and redo some things without affecting what already exists.
But why OOP?
Someone will ask.
Here it will be inevitable to compare the model that works (or "works") with your object proposal.
The most common argument here is to "hit" the current pattern: it’s confusing, disorganized, no pattern, scattered rules, etc. Depending on how the current pattern was implemented, this may help the discussion, but it may not necessarily be true to the standard. Maybe the confusing code in the current pattern is only there because the people who participated in the development don’t want/might/know how to improve.
So I would try to bring the advantages by avoiding the comparisons a little.
Advantage 1: proximity of business
An object organization allows the conversation between business people (Analysts, Pos, etc) and developers to get much more transparent. When speaking that the Pedido
gets a Pagamento
, this will actually be occurring in the code:
pedido.adicionarPagamento(cartao);
With the team’s effort in trying to use the same business language to model objects (known as ubiquitous language).
If your analyst/PO has some technical baggage, it can even help you with some code decisions if you know how to direct it in your understanding of it.
In other solutions you will see something quite different: maybe a DTO
, service classes, validation classes, a repository, mapper, etc. Something more distant from the "reality" of business.
Advantage 2: Code becomes more self-explanatory
Another advantage that I see is that it limits a little the "evil creativity" of developers when organizing the application. As the searchlight of the application are the objects, you will always have a good notion of where to implement a new Feature or make a correction. For example, if you have any validation on the card part, you will search for objects related to Cartao
.
This also leads to a natural movement of organize your system by packages according to business and not by Pattern.
However, in other solutions, this rule may be in some service class, validation class, entity, etc.: Is it in the CartaoService
? RegistrarCartaoService
? CartaoValidation
? ProcessarPagamentoCartaoValidation
?. Anyway, you can use other class names that you think have more meaning, but with the growth of system code this tends to quickly become a problem without a more rigid and clear control for class names and package organization.
Advantage 3: there are simple approaches to applying OOP
You don’t need to rely on dense DDD books to create a robust object-oriented application. There are approaches today, such as the Elegant Objects, which allow the use of object orientation without having to completely isolate its objects, requiring less code "infra" to save information or perform integrations. However, violating some principles considered "sacred". It also brings some welcome practices to the code, such as avoiding null
. But it’s not a recommendation, because he has some views polemical. It’s just an example.
I could think of others yet, but I believe this is a good start.
Show me the code!
Often, it is necessary to literally draw so that people can understand your idea, what you are offering or saying. This is perfectly normal, some people are more visual. In the world of programming this can be achieved with a functional implementation.
Choose some simpler project functionality that already exists, and implement it using OOP. This will allow a comparison between the current model and the object-oriented model you want to propose.
And if he refuses?
You can have the best arguments in the world and not be able to convince your boss. Sometimes, it’s not what you say, but how you say it. Or there may be situations that run away from even his control that prevent this and that he can’t tell you.
Finally, ask him to explain the reason for the refusal if possible and, depending on his answer, ask him what he would need to do to make this possible.
If the question was the other way around, I would answer :) Although OOP, if you look for my answers, you will see that I am critical of the paradigm. At least to his abuse. This website built in language sold as being OO but avoid the paradigm as much as it gives and get better results because of this. There’s a lot of people who think O shows when it’s not true. Many programmers think that using classes is doing OOP, which is far from true. So don’t let him see what I have to say :)
– Maniero
Just my opinion, but if O is not needed so far, maybe the ideal is not to use it even... On the other hand, if you can identify anti-patterns in the codes (e.g., excess of if..LSE that could be best expressed via polymorphism, functions with "strange" names to "help remember" which type they apply to, etc.), then these problems themselves should be used as an argument for change. By the way, I miss functional programming much more when it is not available than OOP...
– mgibsonbr
@Arthurdeandrade, just out of curiosity, what language is used?
– Fernando Leal
@Fernando We have projects in C#, Delphi and PHP. The main and first tool of the same company is Delphi, now newer projects are already being done in other languages like C# and PHP.
– adamasan
Seeing the responses received (including mine), I imagine you might be thinking, "okay, and now how do I explain that for my manager?..." P
– mgibsonbr
It’s @mgibsonbr. I was posting a comment to you at this point when I asked myself this question too. In fact, although complete, both answers do not present strategic arguments that contribute such a great culture change. I think at this point, my unfortunate response was the one that came the closest. After all, all my positions affect a company strategically.
– João Luiz Grigoletti
@andradedearthur Don’t talk to management in "Object Orientation" - talk about the problems of current code and the benefits of "improving software engineering" of the company. The benefits you find in the 3 responses posted so far, including the controversial response of Joãoluizgrigoletti, which, although incomplete, is correct. From what I have seen, prefer procedural in a language that supports very well the most useful paradigms of OO is lack or knowledge of OO (real OO and not the academic one of decades ago) or lack of experience with procedural codes in these languages.
– Caffé