Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+34 votes

What do you prefer, Singleton or Static classes? Why is your choice the superior class form?

asked in CSC285_Fall2018 by (1 point)

1 Answer

+19 votes
 
Best answer

I like static classes, first because Of habit, but also because there are ways to work around the problem of multiple of objects of a class as we saw in class, which I am also familiar with.
The Singleton pattern is definitively useful but only (or maybe I should say mostly) when you want to produce one and ONLY one object of this class. And while having multiple objects when you don’t want to might be bothersome. There are ways of restricting it with static classes too.
For me it’s more like “I want to have the ability to do 10 things but also the ability to restrict the number of things done” instead of “I want to have the ability to do this thing only and exclusively”

answered by (1 point)
selected by
+10

And also i know that some programmers have the philosophy that the user is your code’s worst enemy since it’s the user the one that can break it by doing stuff wrongly. (Like inputing invalid values) but to be fair past classes both in csc211, csc212 and this csc285 class have thought us that you HAVE to be prepared for this kind of inconvenients.

...