Register | Login 
Forum  
SearchForum Home
     
  Study Groups  C# Q&A  Ch 3: Inheritan...
 Ch 3: Inheritance
 
 3/19/2006 10:10:54 PM
AlGonzalez
87 posts
nomadicview.blogspot.com/


Ch 3: Inheritance
So far just one question.

Do most developers define protected virtual events or do they define protected virtual On{eventName} methods to be overridden in a derived class?

Al Gonzalez
P.S. Solutions, Inc.
http://www.linkedin.com/in/algonzalez
 3/20/2006 2:46:07 PM
AlGonzalez
87 posts
nomadicview.blogspot.com/


Re: Ch 3: Inheritance
 Modified By AlGonzalez  on 3/20/2006 2:46:22 PM)
In other words, do you prefer this:

public delegate void PlanetDestroyedEventDelegate(object sender, EventArgs e);
public class HG2TG {

    public virtual event PlanetDestroyedEventDelegate PlanetDestroyed;

    public void DestroyPlanet() {
        // zap
        EventArgs e = new EventArgs();
        PlanetDestroyed(this, e);
    }
}

or this:

public delegate void PlanetDestroyedEventDelegate(object sender, EventArgs e);
public class HG2TG {

    public event PlanetDestroyedEventDelegate PlanetDestroyed;

    public void DestroyPlanet() {
        // zap
        this.OnDestroyPlanet();
    }

    protected virtual void OnDestroyPlanet() {
        EventArgs e = new EventArgs();
        PlanetDestroyed(this, e);
    }
}

Pros? Cons?

Al Gonzalez
P.S. Solutions, Inc.
http://www.linkedin.com/in/algonzalez
  Study Groups  C# Q&A  Ch 3: Inheritan...

Copyright (c) 2008 GSP Developers
Walling Info Systems | Terms Of Use | Privacy Statement