Is a Static Class Possible in OOABL?

Posted by v205 on 02-Nov-2018 15:23

Is it possible to define a STATIC CLASS using OOABL? 

Separate question: is there a point to having a DESTRUCTOR in a CLASS with only STATIC METHODs?

Posted by bronco on 03-Nov-2018 03:21

Well, members (methods, variables, properties etc) are static, classes aren't. You can prevent instantiation by giving a class just a private constructor. This way it cannot be inherited either. If you make the class abstract as well, it cannot be instantiated by itself, leaving only static methods as an option to do something useful.

So if your class is abstract and has only a private constructor (ie it's a "static class") and only static methods there's no point in having a destructor since the destructor is only called when an instance is deleted.

All Replies

Posted by bronco on 03-Nov-2018 03:21

Well, members (methods, variables, properties etc) are static, classes aren't. You can prevent instantiation by giving a class just a private constructor. This way it cannot be inherited either. If you make the class abstract as well, it cannot be instantiated by itself, leaving only static methods as an option to do something useful.

So if your class is abstract and has only a private constructor (ie it's a "static class") and only static methods there's no point in having a destructor since the destructor is only called when an instance is deleted.

Posted by v205 on 06-Nov-2018 17:15

Thanks @Bronco. I think this answers my questions.

This thread is closed