Abstract and final

BlitzMax Forums/BlitzMax Programming/Abstract and final

ziggy(Posted 2008) [#1]
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!


Azathoth(Posted 2008) [#2]
It would be a useless class, you couldn't instance it or inherit it.


ziggy(Posted 2008) [#3]
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


Sledge(Posted 2008) [#4]
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.


Otus(Posted 2008) [#5]
Why does it have to be Abstract or Final as long as you don't extend it or create any object instances?


ziggy(Posted 2008) [#6]
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


Otus(Posted 2008) [#7]
Type StaticClass 'Abstract Final



Brucey(Posted 2008) [#8]
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.


ziggy(Posted 2008) [#9]
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.


Mahan(Posted 2008) [#10]
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.)


Difference(Posted 2008) [#11]
Could you:

Type MyType Final

	Method New()
		RuntimeError "MyType says: Dont new() me. I'm a singleton class with shared members."
	End Method
	
EndType

?


Jim Teeuwen(Posted 2008) [#12]
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.


ziggy(Posted 2008) [#13]
that's great.