Click here to Skip to main content
15,903,203 members
Home / Discussions / C#
   

C#

 
GeneralRe: Class inheritance, forcing new classes to implement certain functions Pin
harold aptroot4-Oct-11 9:48
harold aptroot4-Oct-11 9:48 
AnswerMessage Removed Pin
4-Oct-11 9:27
professionalN_tro_P4-Oct-11 9:27 
GeneralRe: Class inheritance, forcing new classes to implement certain functions Pin
dan!sh 4-Oct-11 9:32
professional dan!sh 4-Oct-11 9:32 
GeneralRe: Class inheritance, forcing new classes to implement certain functions Pin
ExoticmE4-Oct-11 9:52
ExoticmE4-Oct-11 9:52 
AnswerRe: Class inheritance, forcing new classes to implement certain functions Pin
Ian Shlasko4-Oct-11 9:45
Ian Shlasko4-Oct-11 9:45 
AnswerRe: Class inheritance, forcing new classes to implement certain functions Pin
Pete O'Hanlon4-Oct-11 10:19
mvePete O'Hanlon4-Oct-11 10:19 
AnswerRe: Class inheritance, forcing new classes to implement certain functions Pin
jschell4-Oct-11 10:53
jschell4-Oct-11 10:53 
AnswerRe: Class inheritance, forcing new classes to implement certain functions Pin
Eddy Vluggen4-Oct-11 12:43
professionalEddy Vluggen4-Oct-11 12:43 
Member 8209737 wrote:
can someone give me some pointer as to go about this ?

Does it have to be on the class level, or would it be alright to have it at the object-level (say, an event[^]?)
C#
class SomeAnimalClass
{
    public event EventHandler IsWalkin;

    protected virtual void OnWalk()
    {
        Console.WriteLine("Doing walking stuff for " + this.GetType().Name);

        EventHandler isWalkin = IsWalkin;
        if (isWalkin != null)
        {
            isWalkin(this, EventArgs.Empty);
        }
        else
            throw new NotImplementedException("DoWalk isn't implemented in " + this.GetType().Name);
    }

    public void StartWalkin()
    {
        // point in code that's calling the custom Walk-method;
        OnWalk();
    }
}
class Cat: SomeAnimalClass { }
class Dawg: SomeAnimalClass { }

class Program
{
    static void Main(string[] args)
    {
        SomeAnimalClass animal = new Cat();
        animal.IsWalkin += (o, s) => 
            Console.WriteLine("specific walking stuff for this animal of type " + animal.GetType().Name);
        animal.StartWalkin();

        SomeAnimalClass otherAnimal = new Dawg();
        try
        {
            otherAnimal.StartWalkin();
        }
        catch (NotImplementedException nie)
        {
            Console.WriteLine(nie.Message);
        }
        Console.ReadKey();
    }
}

Output;
XML
Doing walking stuff for Cat
specific walking stuff for this animal of type Cat
Doing walking stuff for Dawg
DoWalk isn't implemented in Dawg

Reposted, seems I did something wrong as the prev. post doesn't show up
Bastard Programmer from Hell Suspicious | :suss:

GeneralRe: Class inheritance, forcing new classes to implement certain functions Pin
ExoticmE4-Oct-11 16:38
ExoticmE4-Oct-11 16:38 
AnswerRe: Class inheritance, forcing new classes to implement certain functions Pin
BobJanova4-Oct-11 22:43
BobJanova4-Oct-11 22:43 
QuestionC# and SQL Server - Display Breakdown By Type Pin
Matt U.4-Oct-11 9:01
Matt U.4-Oct-11 9:01 
AnswerRe: C# and SQL Server - Display Breakdown By Type Pin
dan!sh 4-Oct-11 9:29
professional dan!sh 4-Oct-11 9:29 
GeneralRe: C# and SQL Server - Display Breakdown By Type Pin
Matt U.4-Oct-11 9:43
Matt U.4-Oct-11 9:43 
GeneralRe: C# and SQL Server - Display Breakdown By Type Pin
dan!sh 4-Oct-11 10:32
professional dan!sh 4-Oct-11 10:32 
AnswerRe: C# and SQL Server - Display Breakdown By Type Pin
BobJanova4-Oct-11 22:45
BobJanova4-Oct-11 22:45 
GeneralRe: C# and SQL Server - Display Breakdown By Type Pin
Matt U.6-Oct-11 2:08
Matt U.6-Oct-11 2:08 
AnswerRe: C# and SQL Server - Display Breakdown By Type Pin
Shameel4-Oct-11 23:50
professionalShameel4-Oct-11 23:50 
QuestionHow do I generate a Unique AlphaNumeric ID in C# Pin
ebukaegonu24-Oct-11 1:50
ebukaegonu24-Oct-11 1:50 
AnswerRe: How do I generate a Unique AlphaNumeric ID in C# Pin
Not Active4-Oct-11 2:26
mentorNot Active4-Oct-11 2:26 
AnswerRe: How do I generate a Unique AlphaNumeric ID in C# Pin
BobJanova4-Oct-11 2:56
BobJanova4-Oct-11 2:56 
AnswerRe: How do I generate a Unique AlphaNumeric ID in C# Pin
Ian Shlasko4-Oct-11 5:18
Ian Shlasko4-Oct-11 5:18 
AnswerRe: How do I generate a Unique AlphaNumeric ID in C# Pin
Matt Meyer4-Oct-11 6:40
Matt Meyer4-Oct-11 6:40 
QuestionHow do I add row data directly to a DataGrid Class? Pin
Xarzu4-Oct-11 1:24
Xarzu4-Oct-11 1:24 
AnswerRe: How do I add row data directly to a DataGrid Class? Pin
Pete O'Hanlon4-Oct-11 1:29
mvePete O'Hanlon4-Oct-11 1:29 
GeneralRe: How do I add row data directly to a DataGrid Class? Pin
Xarzu4-Oct-11 18:38
Xarzu4-Oct-11 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.