Abstract and final
BlitzMax Forums/BlitzMax Programming/Abstract and final
| ||
Is there any way to make a type abstract and final at the same time? I know this doesn't sound very well, but as BlitzMax doesn't have shared classes, I think making an abstract class with globals instead of types and functions instead of methods would do the job... unless it is extended! |
| ||
It would be a useless class, you couldn't instance it or inherit it. |
| ||
Well, it would be a singleton class with shared members. what in VB.net you call Module, in C# a Static class, etc. I found them useful.Type MyApp Abstract Final Const Version:String = "1.5.0" Const Name:String = "My Game" Function CheckMedia:int() . . . End Function End Type This shared-static classes, that are available on other languages, are usefull basically to organize things. They help keeping the code organized (similar to namespaces). There's no reason to extend them, or to instantiate them. I was just wondering if there's a way to do this on Max |
| ||
Just use the type name as a namespace and use global variables as class variables. Close as you're going to get at the moment, I think. |
| ||
Why does it have to be Abstract or Final as long as you don't extend it or create any object instances? |
| ||
That's the issue. Abstract because I don't want to instantiate it, and final becouse I don't want to extend it. And I don't want to remember in a year that i should not extend or inherit this particular class. That all. this is just a 'cosmetic' question, I like code well organized. But for the answers I'm getting here I supose this is not possible. Thanks to all :D |
| ||
Type StaticClass 'Abstract Final |
| ||
Why does it have to be Abstract or Final as long as you don't extend it or create any object instances? Perhaps more for releasing as a module when you want that kind of functionality, to stop the user from extending your Type and changing the functionality in some way. Otherwise, yes, you would just make a decision not to extend it etc. in your own code. |
| ||
Yes, I was thinking on a version control class for my modules. I don't want anybody to change this (extending the class), and it has no sense to instantiate it. |
| ||
Ah, now i get why you want it. I don't say I don't agree. However I'd say things like general visibility (private/protected/public) per method/constructor/static method not to mention threads would tickle my brains happiness centre more. (Thinking about how often we'd use said functionality.) |
| ||
Could you:Type MyType Final Method New() RuntimeError "MyType says: Dont new() me. I'm a singleton class with shared members." End Method EndType ? |
| ||
Peter Scheutz's solution is the only way to do this in BMax. Not very elegant, but it'll ensure the class is not instantiated. |
| ||
that's great. |