This one is for the java man, and anyone else who knows obj oriented. I came across this question recently.. Any thoughts/answers?
My final question concerns fundamentals of object oriented programming: just what is a protected abstract virtual base pure virtual private destructor, and under what circumstance would one be used?''
Thursday, September 13, 2007
Subscribe to:
Post Comments (Atom)
4 comments:
hahhaaa...ye tumhare doug comer uncle ki kahawat hai na?
Individually all the words make sense, but taken together I have no idea what it is. Java has no destructors. There is a function called finalize(), defined on every Java object, which is a remote cousin of destructor. All functions in Java are virtual by default unless u declare a function as final.
Yours truly,
Java man.
First of all there is no concept of virtual in Java (I know it is there in C++, but I do not C++ well). Every function, as you have noted, is Virtual by default in Java.
Also there is no desctructor in Java, as you have noted, but finalize() function. But this method usage is not advised, rather a Java programmer should go by the GC mostly. Reason being finalize() will be called only once and your purpose may not be server well. Similarly though Java does not guarantee on GC, still then it is favored.
Now putting your question from a Java perspective, it may be like:
When you use a "protected abstract function" and a "normal private function" or
when you use a "protected abstract finalize" and a "normal finalize function"
For the former, as you see, protected means you are limiting the access for subclasses (a limiting on the virtual case, which is fundamental to polymorphism). For pure private functions you are further limiting the possibility. As you may know you can not have private and abstract simulatenously. And of course, when you are talking of abstraction, it means you are giving a free hand to implement to another user.
For the later case, well finalize() is protected and defined in Object, hence the restriction for protected also applies here. You can not define a protected abstract finalize() as such in a Java class. Complier will not allow it. In fact, if you make it abstract, then the class itself will become abstract (another rule in Java). Now why someone will go for a abstract finalize function - there is absolutely no need. Every class you define in Java extends Object, hence you will have finalize() anyway with you. Coming to normal finalize() function, you have to decide when to use - if you are sure it needs to be called only once, and during that time you have an operation to do, go ahead.
Hope it helps.
http://www.allegro.cc/forums/thread/478186/478216
Post a Comment