Answer the question
In order to leave comments, you need to log in
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:
Answer the question
In order to leave comments, you need to log in
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.
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! :)
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 questionAsk a Question
731 491 924 answers to any question