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?...
You must be signed in to leave a comment
3 January 2021, 00:14
Have a look at the Singleton design pattern. Will be used quite often in the upcoming tasks.
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.
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.
3 January 2021, 19:44
OK, thank you:)