|
What? Ask the people who know the most about it?
But they might suggest he RTFM!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello. I have this small video application which uses some threads. Now when a thread is called to open the media player for a media file, an exception is thrown
COM object that has been separated from its underlying RCW cannot be used
What does this exception mean and how can I fix this issue? Thanks for any pointer.
|
|
|
|
|
|
Creaze the COM object in the main thread and use it only there!
|
|
|
|
|
public abstract class NoImplementations
{
public abstract void DoSomething(int arg1, string arg2);
public abstract int SomeInt { set; get; }
public NoImplementations()
{
SomeInt = 34;
}
}
private class sonOfNoImplementation : NoImplementations
{
public override void DoSomething(int arg1, string arg2)
{
}
public override int SomeInt { get; set; }
}
sonOfNoImplementation sonOfNI = new sonOfNoImplementation();
int x = sonOfNI.SomeInt;
I am baffled I can "get away with this."
Appreciate your thoughts !
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
|
|
Basically, I agree, but it's important to understand: this is rationale, not the syntax rule.
Also, it does not address Bill's issue: actually, there is absolutely nothing wrong with having non-virtual method of an abstract class. I explained in my comment below why it is often be important.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: Also, it does not address Bill's issue
Which would be why I marked it as a suggestion, rather than an answer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
All right, it's perfectly fine, I just took a note without any negative connotation.
Please see the comments by Richard MacCutchan and myself. I explained in detail why Bill's code is perfectly fine and safe (just updated).
—SASergey A Kryukov
|
|
|
|
|
You can "get away with it" because abstract classes can't be instantiated.
And because the concrete classes derived from it must implement both the setter and getter properties in order to compile, the abstract constructor can be guaranteed that the property is implemented in all instances.
So it's legal, and will work!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It makes perfect sense. I just changed my comment to the wrong Mehdi's post and stated: abstract class is not a placeholder, not even close. I explained what it is and what is its purpose. And it should add: it should not be used as a substitute of interface.
Having non-abstract methods in an abstract class has more than perfect sense. Such methods are inherited and can be used in derived classes (so they should better be protected). Internal and public methods are even more important: the compile-time type of abstract class is usually used as a base class for some hierarchy of terminal derived classes used in polymorphic set. This is how you work with derived classed: through members of the base class. If such base class method uses virtual methods, late binging mechanism dispatch the calls to the methods of derived classes, so the whole OOP mechanism is leveraged.
There are many cases when this method in abstract class need not to be overridden, therefore, there is no a need to make it virtual or abstract (all abstract methods are of course virtual).
This is the very basic approach in OOD every developer should know and use.
[EDIT]
Now, let me explain why there is no danger in your assignment of the abstract property in a non-abstract (and even non-virtual) method NoImplementations :
This is an instance method. As an instance method, it will need an instance to be called on. Such instance will always be an instance of some derived non-abstract type, because an abstract type won't allow to get an instance. And, such non-abstract type could not be created if SomeInt is not given the implementation. The mechanism of the late binding will use the virtual method table for the setter of SomeInt , according to the runtime type of that non-abstract derived type. Therefore, in all cases where NoImplementations can be called, the setter of SomeInt can also be correctly called and actually assign the property value. No problems whatsoever.
—SASergey A Kryukov
modified 10-Nov-14 17:39pm.
|
|
|
|
|
Countered Univote.
What do you get when you cross a joke with a rhetorical question?
---
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
|
|
|
|
|
Counter countered.
That's how democracy works
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, as soon as you ready to agree with your role of the person which wrong action can be compensated by other public.
You did not even explain your opinion.
Voter always right?
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: You did not even explain your opinion. You don't get an explanation with each vote.
Sergey Alexandrovich Kryukov wrote: Voter always right? Ehr, again; "no".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Of course not. But you decided to write and motivate your vote. You wrote, but not motivated, that's all. And you didn't understand the matter. Look, I don't have problem with you. But I would advise you to understand that everyone can read what you write.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: You wrote, but not motivated, that's all. That would be a waste of time, just as the rest of this thread is.
Sergey Alexandrovich Kryukov wrote: And you didn't understand the matter. That is your assessment.
Sergey Alexandrovich Kryukov wrote: I would advise you to understand that everyone can read what you write. I don't mind
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: This is the very basic approach in OOD every developer should know and use. I'm gonna suffice with a "No".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
So what? Do you understand that you have confessed in your own ignorance?
If some statement makes you feel bad, it does not make this statement false. Any objections? Only, please, on the matter of the subject under the discussion.
—SASergey A Kryukov
|
|
|
|
|
Sergey Alexandrovich Kryukov wrote: Do you understand that you have confessed in your own ignorance? By not agreeing with you?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No, not by not agreeing with me.
—SASergey A Kryukov
|
|
|
|
|
Give up; you'll never win. It's like punching jelly (or jello if you speak American)
|
|
|
|
|
I'm trying to find the nearest number that divides evenly into a pre-defined number.
Examples:
x = 12700000 / y where y is the given number and x is the nearest number that divdes into 12700000 evenly.
y = 6250, x = 6250 (12700000 / 6250 = 2032)
y = 6350, x = 6350 (12700000 / 6350 = 2000)
y = 6260, x = 6250 (12700000 / 6260 = 2028.753994)
y = 6301, x = 6350 (12700000 / 6301 = 2015.553087)
Is there a way to do this using C#?
I'm sorry I didn't explain myself correctly. I have edited the question above.
modified 10-Nov-14 9:10am.
|
|
|
|