Why getter/setter/toString()?

Asked 1 years ago, Updated 1 years ago, 67 views

What is the fundamental reason for gettingter/setter/toString()?

getter

2022-09-21 18:22

2 Answers

Use encapsulation/concealing concepts to restrict access to objects.

Getter/setter is often used to limit direct access to specific data and to modify data through specific methods (public). In my case, I try to refrain from using getter/setter as much as possible, but it's not easy.

There seems to be a lot of debate about this. I think it would be better to establish your thoughts by reading many articles.

It's similar to my thoughts on getter/setter, but I think it's well organized. http://lacti.me/2011/10/03/getter-and-setter-at-java/

There are many reasons for toString() overloading, but the biggest reason is that it is the easiest to express information about an object. If you did not override the toString(), the address value would be stamped. There is a limit to checking the information about the object only with that address value. If you use the output function, it's annoying because you have to set it up one by one.

I want to know the fundamental reason..


2022-09-21 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.