|
So if I wrote
class Farm
{
public void Pet(Cow chicken){}
}
I can access both Foo and Moo?
But if I wrote
class Farm
{
public void Pet(Animal man){}
}
then I can only access the Foo method?
Lol..nice example though....clarification is needed if you don't mind
|
|
|
|
|
sundeepan wrote: Cow chicken
and
sundeepan wrote: Animal man
was a really comical. Anyway i don't see any clarification to make since it is just as you say. When you inherit, you get the members you inherit and in addition any member you make in the new class. Just like if someone left you some items to travel to an unknown land ( ) then, you'd have the items you originally owned plus the ones he left you. But he would not have the items you own since you never gave it to them.
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
sundeepan wrote: why should one not pass an object of a base class
Who says you shouldn't? There are many cases where you would.
|
|
|
|
|
This is the paragraph that threw me off:
"Another benefit of inheritance is the ability to use derived classes interchangeably, a concept called polymorphism. For example, there are five classes that inherit from the System.Drawing.Brush base class: HatchBrush, LinearGradientBrush, PathGradientBrush, SolidBrush, and TextureBrush. The Graphics.DrawRectangle method requires a Brush object as one of its parameters however, you never pass an object of the base Brush class to Graphics.DrawRectangle. Instead you pass an object of one of the derived classes. Because they are each derived from the Brush class, the graphics.DrawRectangle method can accept any of them. Similarly if you were to create a custom class derived from the Brush class, you could also pass an object of that class to Graphics.DrawRectangle. "
|
|
|
|
|
It sounds like the author isn't a very good technical writer. Which is one of my complaints about mass-market programming books. And one of the benefits of taking a class with a real live teacher -- you can ask the teacher for clarification.
That may not be a good example -- System.Drawing.Brush is abstract, so you can't have an instance of it anyway. But if you do have an instance of it, then you could go right ahead and pass it (but who knows what would happen).
|
|
|
|
|
Its a "Microsoft Press" book for the 70-536 cert exam...this guy better be a good technical writer lol!
|
|
|
|
|
I actually almost say the contrary is true.
Mark Nischalke's answer holds true, you do have access to both the Moo() and Foo() methods by passing the subclass. However to do so couples the method to the subclass, and other instances of the animal class cannot be passed:
class Program
{
static void MakeAnimalSpeak(Animal animal)
{
animal.MakeNoise();
}
static void MakeAnimalSpeakCoupled(Cow animal)
{
animal.MakeNoise();
}
static void Milk(Cow animal)
{
animal.Milk();
animal.MakeNoise();
}
static void Main(string[] args)
{
Cow cow = new Cow();
Duck duck = new Duck();
MakeAnimalSpeak(cow);
MakeAnimalSpeak(duck);
MakeAnimalSpeakCoupled(cow);
Milk(cow);
}
}
abstract class Animal
{
public abstract void MakeNoise();
}
class Cow : Animal
{
public override void MakeNoise() { Console.WriteLine("Moo"); }
public void Milk() { Console.Write("Sloooosh"); }
}
class Duck : Animal
{
public override void MakeNoise() { Console.WriteLine("Quack"); }
}
Of course it is horses for courses, as with everythign in the code world. In the example Mark gave, you should pass the cow if you need access to both Moo() and Foo() but otherwise IMO is is better to pass an Animal instead. Better yet, coding to Intefraces produces cleaner results still, and helps with testing (as mock objects can be passed more easily)
Cpianism: I have a negative number in my Rep so please fix it.
Chris Maunder: That isn't a bug.
|
|
|
|
|
This is great, I like the humor involved too. I am saving this reply as a PDF on my computer.
Thanks again!
|
|
|
|
|
Hi,
I had a question regarding the Windows Aero Glass Feature, found in Windows API Code Pack. This feature is not included in Windows XP and Vista, I believe. So if the GlassForm is shown in Windows XP, will an error be thrown? or will the GlassForm window be shown, without the aero feature and without anyerror error?
To be more clear: What will happen if the GlassForm is show in Windows XP/Windows Vista?
Thanks,
Harsimran Singh
|
|
|
|
|
WPF also allows aero to be forced on an app, but when you do that, the appropriate DLL is already in the GAC on the user's machine (because they're running the appropriate version of .Net. I suspect that if you include a CodePack assembly in your references, the appropriate DLL will get copied to your bin folder.
Try it and see...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Even if I try that, I can't test it. I don't own a XP or a Vista machine. I only have Windows 7.
For more information, you should check out my article: Windows 7 FTP Application
It only runs on Windows 7, because of the Windows 7-specific features. I can control other windows 7-specific features on Windows XP/Vista using if(CoreHelpers.RunningOnWin7), however, some of my forms use the glass form. which I can't really control using CoreHelpers.RunningOnWin7, because a Form inherits from GlassForm to use the GlassForm feature.
First question would be: What happens if GlassForm is shown in Windows XP? Will an error be thrown? It doesn't matter if the aero feature is not shown, since it is Windows XP/Vista. I only require the glass feature in Windows 7.
I hope I am clear,
Thanks,
Harsimran Singh
|
|
|
|
|
Pathachiever wrote: It only runs on Windows 7, because of the Windows 7-specific features.
If it only runs on Windows 7, then why are you asking about XP? If you don't want it to to run on XP, then do a Windows version check before you display the first form, and terminate the program if it's running on XP.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Sorry. I knew I wasn't clear on my side.
Actually, I want the application to run on Windows XP. However, I don't know what will happen if the application is ran on Windows XP, since Windows XP probably does not support the glass form feature.
I hope I am more clear now. I just need to know what will happen when the Glass Form is shown in Windows XP.
Thanks,
Harsimran Singh
|
|
|
|
|
Then run it on XP (in a VM if necessary) and see what happens. If you're not doing anything to actually skin the forms, it should fall back to whatever the host OS is capable of..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Trying to make an update function for lets say apples
Apple Table contains color and size and ID
lets say i have 10 apples
and i navigate to apple 5, how can i determine what its ID is ?
Basically the bindingnavigator would say 5 of 10 but what if I seeded my identity column starting with 200
obviously simply id = applebindingsource.position +1 will not work...
I thought maybe making a
List<apple>tempapple = null;
tempapple = db.apple.tolist();
currentapple id = tempapple[applebindingsource.position + 1].ID;
but that doesn't appear to work either cause it's out of range
any help on this would be great...
|
|
|
|
|
Doesn't the object contain the ID?
|
|
|
|
|
I am writing an application in C# and want to use the objects I created in C++, but don't want to have to rewrite them in C#. I've read that you can do it using the IJW mechanism, but I don't fully understand it. If I am compiling my C++ class with /clr, what then do I have to do to be able to make an instance of that object in C#.
Thanks
|
|
|
|
|
|
Hi,
I made a sample remoting library and a simple windows application to run and stop the remoting service. When I start for the first time it is starting fine, but when I stop and start it it is giving me following error.
Only one usage of each socket address (protocol/network address/port) is normally permitted Can anybody help me inthis regard.
My code is as below.
private void Run()
{
ArkClass.running = true;
channel = new HttpServerChannel(1111);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ArkClass),
"ArkClass", WellKnownObjectMode.Singleton);
}
private void btnRun_Click(object sender, EventArgs e)
{
try
{
Run();
MessageBox.Show("Server is Running", "Info", MessageBoxButtons.OK,MessageBoxIcon.Information);
btnRun.Enabled = false;
btnShutdown.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show("An error has occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine(ex.Message);
}
}
private void btnShutdown_Click(object sender, EventArgs e)
{
MessageBox.Show("Server is shutting down", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnRun.Enabled = true;
btnShutdown.Enabled = false;
ArkClass.running = false;
}
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
sounds to me like .running = false is not stopping the remoting channel, unregistering the port correctly!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
My program watches C:\Incoming using .Net 3.5's FileSystemWatcher with the following paramters:
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Path = @"C:\Incoming";
fsw.IncludeSubdirectories = false;
fsw.EnableRaisingEvents = true;
static void fsw_Created(object sender, FileSystemEventArgs e)
{
while (!FileReady.isFileReady(e.FullPath))
{
Thread.Sleep(2000);
}
}
The C:\Incoming directory is shared for network access. If I manually copy a file to the directory from another machine it sees it fine and processes it. However, if I download a similar (or the same) file from a website in IE and have it save to that mapped drive (shared directory) nothing happens.
Anyone know why FileSystemWatcher doesn't see it and how to resolve the issue?
- Joshua
|
|
|
|
|
I just tried it with your code and it seemed to work fine. I replaced all your logic in fsw_Created with a MessageBox.ShowDialog and it popped up 2 or 3 times when I downloaded and saved a file to the C:\Incoming folder.
Perhaps the logic in FileReady.isFileReady is doing something funky? Maybe it's throwing an exception? One thing to watch out for is that IE downloads the file to a temporary folder first, then copies it over from that temp folder to the destination. That could maybe cause some issues.
|
|
|
|
|
Thank you for testing the code. My question is: Did you save the file downloaded from IE to a mapped drive shared on a second computer and not to a local directory?
|
|
|
|
|
There is no resolution to the problem. The FSW was designed to work with local filesystems, not network ones. Read up on this list[^].
|
|
|
|
|
Dave:
Thank you for your response. From what I gather in the google search you sent me it seems people are trying to tell the FileSystemWatcher server to watch a mapped drive (i.e. creating a mapped drive to a share somewhere else, setting it as M:, and then telling the FSW to watch M:\).
That is not what I'm doing. I have the FSW installed as a service on a server running local to that machine so that it is watching the local C:\Incoming. So I don't think it should matter if I'm copying a file locally or via the network to that shared folder from a third-party machine.
Here is some additional information that may help explain where I am. I can copy a file to that share from my workstation and the FSW will work no problem. But if I download a file on my workstation and tell IE to save it to my I: drive (which is a mapped drive to that share on the server where FSW is) nothing happens.
So, I'm thinking that it has something to do with how IE is writing the file to a share and not triggering a CREATE even for FSW to see? Make sense.
|
|
|
|