I need to consult about this code!
Hello so I'm trying to write a code and i wrote in the properties a condition that if the username is null or empty to show a message which in this case it doesnt.
Here is the code and thank you for your time!
24 Replies
well, you never actually use the setter
but i also would not put this code in a setter, setters should be pretty simple validation and not do anything extra like printing
can you give me an example if okay?
if i wanted to stop username from being set to an empty/null string i would check it and throw an exception if it's invalid
it's about keeping responsibilities separate, your customer class doesn't have a good reason to know anything about the console
Im not going to lie but im still not understanding
You're setting the field
Not the property
So you completely bypass anything and everything the property has
Oh okay thank you :d
š *
I got it a little ill do more research in advance
wrote this but still the same thing
Are you actually setting
UserName
?
Or _userName
?
Also, your setter doesn't actually set anything nowright now my head is about to explode and i dont know what i did
more adecuate asnwer is i dont know what im setting
in your constructor you're setting
_userName
not UserName
ohhhhhhhhhhhhh
this will not call the setter for UserName
okay okay
i got it thank you for clarifying
š
just to make sure get its for (To get the data that is in the memory) and setter (Its about the user to be able to change the data)
Basically
$getsetdevolve
can be shortened to
can be shortened to
can be shortened to
can be shortened to
Maybe this will clarify what getters and setters really are
okay thank you
understood
š
thanks for your help
:Ok:
:harold:
Is this a bot command? If yes, where could I get them?
It is, yeah. All the tags should be listed on mod.gg, not sure if you need any special role to see them
$getsetdevolve
can be shortened to
can be shortened to
can be shortened to
can be shortened to
There are commands on mod.gg but I think this getsetdevolve does not require any command.