Does it have any sense to make a setter method private (in a real program)?
Nobody will be able to change that private variables, because of: the private setter method also uncallable.
(In this task we had to make the setter method private.)
Private setter method?...
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Nouser
3 January 2021, 00:14
Have a look at the Singleton design pattern. Will be used quite often in the upcoming tasks.
0
Gellert Varga
3 January 2021, 13:40
Thanks, but I'm sorry, i don't know what means "singleton" - so i don't understand anything from this article. At my level this article is too difficult for me.
0
Nouser
3 January 2021, 14:05
In short the singletons purpose is to make sure only one object of a class gets instanciated. For example you can use that for program settings. The private constructor doesn't allow creating objects. For that you need to use a static method. That one checks if there already is an instance and either returns that instance or a new object.
I have forgotten when that pattern first gets introduced here but it is not far away anymore.
+1
Gellert Varga
3 January 2021, 19:44
OK, thank you:)
0