|
I need to create two different classes which differ only in the data member types. The first class is an "IntegerPoint" class, using integer values for the x and y. The second class is a "DoublePoint" class, using double values for the x and y.
These classes have extensive operator, method, etc. functionality. But all of the functionality is identical, again the only difference is the data member type.
Does anyone know what the "best practice" is for handling this type of situation? Can some form of inheritance be used here?
Mark Sanders
sanderssolutions.com
|
|
|
|
|
first a question:
do you need two implementations - are you having two because you are worrying about performance?
why not just have a DoubmePoint class - see if you have a problem then.
if that does not work then:
create a class called SanderNumber which can use either a integer or a double.
then create your abstract class SanderNumberUtil that uses SanderNumber.
then create a concrete class for integer and double.
This puts most of the complexity into SanderNumber - but allows you to use it polymorphically.
hope this helps.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
why not just have a DoubmePoint class
I am not sure what you mean by "DoubmePoint class".
if that does not work then
I somewhat understand the theory of what your second solution is but I also can't really invision it very well. Could you give a little more detail?
Mark Sanders
sanderssolutions.com
|
|
|
|
|
type - i meant why not just have the DoublePoint class - do you really need the integer class?
otherwise
class SanderNumber
{
bool _isInteger = true;
int _valueInt;
double _valueDouble;
public SanderNumber(int value)
{
_valueInt = value;
}
public SanderNumber(double value)
{
_valueDouble = value;
_isInteger = false;
}
public int SomeFunction()
{
// if (!_isInteger) throw(some exception)
return _valueInt;
}
public double SomeFunction()
{
// if (_isInteger) throw(some exception)
return _valueDouble;
}
}
class SanderUtil()
{
SanderNumber _number;
public SanderNumber(SanderNumber value)
{
_number = value;
}
public SomeCleverStuff()
{
if (_number.SomeFunction()) > 24.0)
return;
}
}
this would give you what you want and would be type safe.....
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
You could implement an Interface for your methods which the two classes will inherit and have to implement. That is if the implementation of the methods are different.
|
|
|
|
|
|
you could make the integerPoint class, then derive the doublepoint class from that, and override the variables/properties inherited....just a thought.
| Website: http://www.onyeyiri.co.uk
| Sonork: 100.21142 : TheEclypse
| "If a dolar was a chicken would the chicken be evil?"
|
|
|
|
|
I'm writing my first C# Windows Application using Win Forms. The program, a simple utility, is very processing intensive. Once the processing begins it continues for several minutes.
I need the program to process UI messages while it is processing data, obviously. I'm not sure how to do this using the runtime.
Would some kind person please point me in the right direction?
Roger
|
|
|
|
|
Well this involves some long explanation. It involves some windows understanding before you begin. What's important is that once the process is finished , it must call back on the windows message loop's main thread. I have the perfect article for you. Tale the time to read it. It's worth it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
|
|
|
|
|
My first thought would be to use the System.Threading class. Simply set you processing function as a thread and let it run simultaneously as your main thread.
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
The problem here is what happens if you want to be notified, when your thread is complete. That may be the case for many UI apps.
The article I have mentioned explains all this.
Cheers
|
|
|
|
|
Well, just add a MessageBox function add the end of the method that contains your process
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
Not exactly. Again, in most cases you want to do more than add a message box. Say for instance that when the process is finished, you want to write something to a textbox on that form. You MUST NOT update the textbox in the new thread. That is a no no in Windows. You must only update controls on the windows main thread (the win proc).
The article I've already mentioned explains all this. Take the time to read it, it's informative and it helped me alot as well.
|
|
|
|
|
Cool. Will look it up.
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
It is strange, anyone say : "it must be true", but .NET "no, rectangle isn't visible" !!!
RectangleF clippingRectangle = new RectangleF(0.0160072f,0f,0.002000898f,0.3201439f);
Region region = new Region(clippingRectangle);
bool success = region.IsVisible(new RectangleF(0,0,150,150)); // return false !!!
Have you idea how can I correct it ?
Please
Wizard_01
|
|
|
|
|
I've found by experiment that the problem is with the width (0.002...). If either the width or the height of the rectangle used to create the region is less than 0.03125 then the problem occurs. I've also found that
region.IsEmpty(myform.CreateGraphics())
returns true if either the width or height is less than this value.
I'm afraid I've no idea why a width/height of less than 0.03125 makes a region empty, or what you can do about it (except check for a size less than this and make it bigger). 0.03125 = 1/32, so maybe this is some "magic number" used within GDI+?
Chris Jobson
|
|
|
|
|
Ohhh
I use this for zoom in/out in my new control. (I was so lazy to recalculate everytime when zoom has changed cell-region and rectangle to new values)
Maybe it necessery but slower
Do you know how can I region flow by 1 pixel ? (I can be enoght in this case for me )
Thank you ...
Wizard_01
|
|
|
|
|
Right. As a feature in my Animation engine, I want to be able to read an XML file for frame information.
In the engine I have an enum for storing specific types of frames.
For example one being for where the bitmap of the frame is stored.
public enum BitmapLocations
{
InExe,
Filesystem
}
Now, I have a dataset for reading an XML file into. I can cast any standard types easily. Such as:
(string)row["name"]
But when it comes to this enum value, I keep getting an invalid cast exception. I've tried:
XML:
<location>InExe</location>
C#:
(BitmapLocation)row["location"]
And this throws the exception.
I've also tried assigning the enum values to a number and using that instead, but still no luck.
Any ideas?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
BitmapLocations dummy = BitmapLocations.InExe; // dummy assignment, does not matter
String s = "Filesystem";
// convert string to enum
BitmapLocations bl = (BitmapLocations) Enum.Parse(dummy.GetType(), s);
|
|
|
|
|
Hi,
We are soon going to start to distribute .NET components/controls.
If you have something for .NET you think could be sold please contact us at info[at]compona.com for more info.
//Roger
|
|
|
|
|
Hey .
As I understood , this property , if set explicitly , should
disable the autmatically expantion of the array when using "Add" ,when the Count equals to Capacity ..
well .. this doesn't work for me .
I just don't want the ArrayList to be expanded automatically when adding item , when Count equals to Capacity.
instead I'd expect that it will raise some exception .
of course I can do all that in my own class that using the ArrayList , but
I'd like that to be done in ArrayList itself .
anyone knows how to do it ?
Alex
ICQ : 10676475
email : alexyag@inter.net.il
===================================================
"The harder you fall, the higher you bounce." - American Proverb
|
|
|
|
|
I'm pretty sure Capacity just pre-assigns the memory, so if you have 5 items and a capacity of 10 then it's holding on to the memory for the other 5. But then when you put the 11th item in, your Capacity is increased to 11.
What do you actually want to do when item 11 is added?
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Paul Riley wrote:
I'm pretty sure Capacity just pre-assigns the memory
Yes.
public virtual void System.Collections.ArrayList.set_Capacity(int value) {
object[] local0;
if (value != (int) this._items.Length) {
if (value < this._size)
throw new ArgumentOutOfRangeException(...);
if (value > 0) {
local0 = new Object[checked((uint) value)];
if (this._size > 0)
Array.Copy(this._items, 0, local0, 0, this._size);
this._items = local0;
return;
}
this._items = new Object[16];
}
}
|
|
|
|
|
You can fix the size of the ArrayList like so ...
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add( "The" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumped" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
// Create a fixed-size wrapper around the ArrayList.
ArrayList myFixedSizeAL = ArrayList.FixedSize( myAL );
An exception will be thrown whenever yuo add or remove an item from
the array. However, you can modify the items currently in myFixedSizeAL.
|
|
|
|
|
In SQL Server is it possible to have a trigger that will throw an event which could be caught by C# program running in the back ground?
Is this even possible? If it is, have u any links to help/examples?
a better description of the problem...
What I want to happen is that when we import data in to our database
(INSERT) that a trigger is called.
The trigger passes that data into a validation tool that cleans that
data and writes it back to a new clean database.
There needs to be two tables, one containing the raw original data and
one containing the cleaned up data.
The reason this is not done using a program to load the data is to
ensure any data loaded in to the database is cleaned.
Tommy
|
|
|
|