Похожие чаты

Hello Guys, as a college student who was drilled to use

encapsulation in every class where variables are set/reset

What do you think of it? Personally I see little reason in hiding fields behind getter/setter methods if no additional checks are in place.

Am I missing something? When coding alone what benefit do I get from hiding fields behind set methods?

5 ответов

18 просмотров

You are right, there is no real benefit of get and set if you just want to have a public field. But in case you have a code associated with get or set, like if you get something and you want your class to go and get something from internet or database it is worth it... Or if you set something and your class will change color of something that is where get / set works good, otherwise use public field... it is as good.

Christoph- Автор вопроса
Talula
You are right, there is no real benefit of get and...

At my university it was solely used to change private fields, with no checks happening whatsoever Thanks for the heads up :)

You can also think of scenario where you want to increment or multiply value of variable when you set it or get it. Most of unit conversion and all related things.

If you decide to add those checks later to a public field you’ll need to recompile all of its clients and if it already had a getter/setter you only need to recompile the library itself

Christoph- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта