Overriding a class

Posted on 2012-09-13
Last Modified: 2012-09-13
When overriding a class such as:

       public override void OnCreate()

Open in new window

Is it best to call the base method BEFORE or AFTER your code? And reasons why please.

Thanks :)
Question by:zattz
    LVL 43

    Assisted Solution

    >>Is it best to call the base method BEFORE or AFTER your code?

    Depends on what you do.  Sometimes before, sometimes after, sometimes makes no difference.
    LVL 74

    Accepted Solution

    Well typically the base implementation is what actually raises the event. The decision you have to make is whether not you want the client to see the event before your code runs or after your code runs, or to never see it all. ( more or less what Andy said. )
    LVL 10

    Assisted Solution

    by:John Claes
    Example :

    For Constructor you mostly set it first : you are then sure that it's constructed
    For destruction set is as last : you want it to be destructed after you've destructed all the addon's

    For the other methods, it's all about what the others said, just trying to clear it out a little more with the 2 examples
    LVL 43

    Expert Comment


    Very good point, re c'tor and d'tor

    Author Comment

    I guess I'll have to try it out and see what works best. I'm developing for Android, so I'm in the dark mostly :) Thanks for the help
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Not to discredit my fellow experts, but you might try posting your question in the Android TA. (Myself, I have only dabbled in Android development.)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now