L
L
Levingstone2021-02-24 14:44:16
OOP
Levingstone, 2021-02-24 14:44:16

Best way in terms of OOP?

I’ll ask a slightly stupid question, but then I thought, what is the best way to provide an array, say, from a class to a function, from the point of view of OOP?
Publish an existing object and give access to it through a dot (read-only, not for modifications)
Or create a method like public: List get_list() and return this array, reading it through this method, and make the array itself private?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VitalyChaikin, 2021-02-24
@Levingstone

in my opinion, from the point of view of OOP (namely, encapsulation), - access to a variable / array is possible only from a class function; And so get() and set() must be implemented for this variable.

S
Saboteur, 2021-03-10
@saboteur_kiev

The whole essence of OOP is that outside you can not work with any data of the class, only through methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question