|
One of the reasons I can think of is that you don't want a programmer to break some important functionality.
For example:
sealed class RegulateControlRods
{
if (power > 10MW) LowerRods();
if (power < 5MW) RaiseRods();
}
or perhaps change its interface to other classes. For example:
public class RegulateControlRods
{
if (power > 10MW) LowerRods();
if (power < 5MW) RaiseRods();
}
public class HomerSimpsonNuclearPowerPlant : RegulateControlRods
{
if (power > 10MW) RunLikeHell();
if (power < 5MW) GoEatADohnut();
}
However, sealing things like "Point"???
Sometimes I think both C# and .NET were the result of some highschool student's finals project in Computer Science 101.
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
|
|
std::string is the same, only the compiler does not enforce it, only the absence of virtual destructors indicates that deriving from it is not what the implimenters want. Use has-a rather than is-a to extend these classes.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
It's not a waste of time, it's good design. The resultant class will not be derived from String, it cannot take the place of a string. This is by design. I like it. You should read 'Design and Evolution of C++' to get some insight into this sort of stuff.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I'll take a look at the book, but it does seem very inconvenient, because if I wanted it to act like an "is-a" class I'd have to write pass-throughs for all the base class's methods. For something like String, this is a lot!
Incidentally, this is also why I'm not very enamoured with interfaces. The derived class ends up having to write the implementation.
Maybe I'm missing some core paradigm shift in OO programming.
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
Marc Clifton wrote:
because if I wanted it to act like an "is-a" class I'd have to write pass-throughs for all the base class's methods. For something like String, this is a lot!
The point is that this is by design, it's a feature for the benefit of class implimenters. I was pretty annoyed that I could not derive from std::string also, but once I knew the reasons I was fine with it. Incidentally, C++ would let me derive from std::string, all they could do was write it so that anyone who knew what they were doing would know it was a bad idea. C# is etter in that it allows you to generate a compile error if you derive from a class which the implimenter did not want you to.
Marc Clifton wrote:
Incidentally, this is also why I'm not very enamoured with interfaces.
I don't like interfaces/no multiple inheritance either.
Marc Clifton wrote:
Maybe I'm missing some core paradigm shift in OO programming.
There's no paradigm shift that I can see, it's simply the ability to enforce something that you could only strongly suggest in C++.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Point is sealed because it is a struct, and structs don't allow inheritence.
String is sealed because if some things were to change with its behavior it would cause vast shockwaves to flow throughout the framework because the way it is used is based on its implementation. If you were to modify String so that strings could mutate then vast portions of the framework wouldn't work correctly because the framework assumes string can't mutate.
As someone else pointed out, allowing some classes to be derived from could cause problems security wise.
James
[edit]fixed typo[/edit]
[edit2]yeesh, I think I need some sleep, clarified point about string[/edit2]
"The elastic retreat rings the close of play as the last wave uncovers
the newfangled way.
But your new shoes are worn at the heels and
your suntan does rapidly peel and
your wise men don't know how it feels to be thick as a brick."
"Thick as a Brick" from Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
String may be sealed simply because it is a "special" object. The .NET runtime does some things with strings internally that you can't do by using a String object, mostly in the name of efficiency. For instance, a "mutable" String is used inside the StringBuilder class, producing a much more efficient implementation. Change the implementation of String, and you don't just get errant code - you might get GPFs, memory leaks, or corrupted memory.
|
|
|
|
|
JasonSmith wrote:
Change the implementation of String, and you don't just get errant code - you might get GPFs, memory leaks, or corrupted memory.
Even worse, if you mutate a string using unsafe code the program works great only the output is a bit funky.
Someone posted some code doing this in the Soapbox quite a while ago, but essentially because of string interning you can change the textual representation of some things like True and False, that are output by boolean.ToString()
String interning is another optimization that wouldn't be possible if strings were allowed to mutate. If two strings are interned, then you can compare them by simply comparing the references or their location in the internal cache of strings. If they aren't interned, or you need case-insensitive comparisons then you need compare each character in both strings.
James
"The elastic retreat rings the close of play as the last wave uncovers
the newfangled way.
But your new shoes are worn at the heels and
your suntan does rapidly peel and
your wise men don't know how it feels to be thick as a brick."
"Thick as a Brick" from Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
Marc Clifton wrote:
Specifically, why are classes like Point and String sealed?
Jason mentioned something that got me to remember another reason for sealing classes. JIT optimizations when dealing with virtual methods
If you have a virtual method in a class and you seal one of its child classes the JIT can produce code to call the child class' implementation instead of going to a vtable approach that would otherwise be needed.
It still needs to rely on the vtable if the variable is of the parent class type, but when you specify the child class it isn't needed.
Sorry of that last paragraph didn't make sense, I couldn't think of a better way of describing it
James
"The elastic retreat rings the close of play as the last wave uncovers
the newfangled way.
But your new shoes are worn at the heels and
your suntan does rapidly peel and
your wise men don't know how it feels to be thick as a brick."
"Thick as a Brick" from Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
|
Can anybody tell how to call GetIPictureFromPicture(Image image) method using C#.
regards,
sns
|
|
|
|
|
using System;
namespace OffAutomation
{
///
/// Summary description for Class1.
///
public class ImageConverter: System.Windows.Forms.AxHost
{
public ImageConverter():base("59EE46BA-677D-4d20-BF10-8D8067CB8B33")
{
//
// TODO: Add constructor logic here
//
}
public static stdole.IPictureDisp ImageToIpicture(System.Drawing.Image image)
{
return (stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image);
}
}
}
this is the way u have to write a class...
and call like this
Image img = System.Drawing.Image.FromFile(@"F:\yicon.ico");
stdole.IPictureDisp obj = OffAutomation.ImageConverter.ImageToIpicture(img);
|
|
|
|
|
Ok, I got that djgpp compiler set up. I think. Compiles the program,no errors,
but it don''t out put an exacutable (.exe). The docs only deal with basic instructions,
no trouble shooting tips at all. Trust me, if I could aford a real compiler,
I'd get one. How much $ for the stuff you folks are using ?
|
|
|
|
|
I don't know whqat djpp is, but I am assuming you are looking for a C# compiler, b/c this is a C# board. Nonetheless, you can download the .NET Platform SDK for free, which includes compilers for C#,VB.NET,MC++.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Thanks , I'll give it a try.
djgpp is a free compiler for C and one for C++, and assembler, with about half the
support needed.
|
|
|
|
|
Hello,
I am trying to pring a crystal report with parameters without previewing it first.
I succeeded to pring report without parameters with the ReportDocument object.
I succeeded also to print report with parameters (I inserted parameters to ParameterFields and put it in crystalReportViewer.ParameterFieldInfo) from the CrystalReportViewer but in this way the report is open in another window, and then I print it from the object.
But I want to print the report with the parameters without showing it on screen first, how can I do it?
Thank u for any help, sharon
|
|
|
|
|
ok I did it :
<br />
ReportDocument report = new ReportDocument();<br />
report.Load(@"G:\Rp3Receipt.rpt",OpenReportMethod.OpenReportByTempCopy);<br />
ParameterFieldDefinitions parametersColl = report.DataDefinition.ParameterFields;<br />
ParameterFieldDefinition paramName1 = parametersColl["prmNameInReport1"];<br />
ParameterFieldDefinition paramName2= parametersColl["prmNameInReport2"];<br />
<br />
ParameterValues values = new ParameterValues();<br />
ParameterDiscreteValue val = new ParameterDiscreteValue(); <br />
val.Value = paramValue1;
values.Add(val); <br />
paramName1.ApplyCurrentValues(values); <br />
values = new ParameterValues();<br />
val = new ParameterDiscreteValue();<br />
val.Value = paramValue2; values.Add(val); <br />
paramName2.ApplyCurrentValues(values); <br />
<br />
report.PrintOptions.PrinterName = @"\\...\HPLaserJ5";<br />
report.PrintToPrinter(1,false,1,1);<br />
|
|
|
|
|
Hi,
I have been trying to find a solution to compile the audio library to dll files or any other format to save my files from being used by any other programmer but no one yet got the naswer!!
If I have 3 audio files and want to compile it indivisualy to DLL (or any other format) then create Windows application and read it without decompile it temporary on the hard disk.
Don't you think it is possible to do it?
How?
Can I have trusted example?
Jassim Rahma
|
|
|
|
|
Since DirectX 9 has been releases you can use DirectSound, which will let you use .NET Stream objects (and MemoryStream objects) for playing the sound.
One of the samples (PlaySound) included with the SDK shows you how to play audio files from the hard drive. All you *should* have to do is change it so one object uses a constructor taking a System.IO.Stream instead of the filename used in the sample.
[Line 173 of main.cs in the sample
change
<small>ApplicationBuffer = new SecondaryBuffer(name, ApplicationDevice);</small>
to
ApplicationBuffer = new SecondaryBuffer(myStream, ApplicationDevice);
Where myStream is a Stream returned from GetManifestResourceStream in our prior conversation.]
In doing so you will require your users to have DirectX 9 installed, which isn't something most users will have until some popular games come out using it. IMHO, just playing sounds isn't a very good reason to require DirectX 9, but I don't know everything about your program so it may be deserved.
HTH,
James
"The elastic retreat rings the close of play as the last wave uncovers
the newfangled way.
But your new shoes are worn at the heels and
your suntan does rapidly peel and
your wise men don't know how it feels to be thick as a brick."
"Thick as a Brick" from Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
I'm using the following code to send an output string to a printer but I need the printer to write it from Right to Left instead of Left to Right because otherwise it will be impossible to adjust specially with long text...
PrintFont = new Font("Tahoma", 10);
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = pd.PrinterSettings.PaperSizes[(int)myRegistry.GetValue("Paper Size")];
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
Jassim
|
|
|
|
|
Is it possible to derive a class from RichEditBox and do my own painting? I've tried deriving from 'OnPaint' but the function never gets called, and theres no 'OwnerDrawPaint' or similar event. Is there anyway of doing my own painting?
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|