N
N
Nikita Egorov2018-06-27 21:42:46
JavaScript
Nikita Egorov, 2018-06-27 21:42:46

How to write in OOP?

Hello.
I'm already familiar with OOP and I like everything about it. When I was still reading a book on Java, looking at examples of using OOP and doing my homework (according to the book), my inner perfectionist was happy. After that I got acquainted with JavaSript, and later with ES6. I recently came up with a project (plugin), and while writing, I came across the fact that everything comes down to procedural style.
That is, there is a plugin, and the following methods:

  1. Input Parsing
  2. Creating an XMLHttpRequest Object
  3. Specific request handling
  4. Output of received information to the user

The result is a class that has these 4 methods. I call all these methods in the constructor. That is, it turns out, I just stuffed the procedural style into the class.
How to properly structure such projects (simple). Or is there no way to do this with OOP? And where then in general use OOP?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Adamos, 2018-06-27
@svupol

OOP is a computerized dream of a handbag. Which is big on the inside and tiny on the outside.
The main thing in a good class is an interface that allows you not to think at all about what is inside the class.
Imagine a black box that solves your problem. Formulate what external data should be enough for it and what external features and logic this box should have. Diligently abstracting from what will happen inside (procedural programming teaches you to think about it, you have to strain).
The simplest example is jQuery.cookies. Cookies in the browser are stored inconveniently for editing, but these are problems inside the black box, they should not be outside. Outside, you need to put a cookie and read the cookie. With a short list of possible properties. This is the class that implements it, quite successfully. Literally one way.
Could this method be a simple procedure? Oh sure. But just that - it doesn't matter.

D
Dmitry Pavlov, 2018-07-05
@dmitry_pavlov

The vast majority of modern programming languages ​​support the ability to use multiple programming paradigms . In which paradigm to write is the programmer's business. I personally see only pluses in the fact that the programming language is flexible in terms of choosing a paradigm. JavaScript, in my opinion, is one of the most flexible languages, and when the stereotyped thinking inherent in a programmer in the early stages of entering the profession ceases to interfere, it becomes, as they say, a powerful weapon in capable hands. Dare! :)

V
Vladimir Kochergin, 2018-07-05
@k4ir05

In this case, no way. Do not use OOP where it is not needed at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question