Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:35:02+00:00 2026-05-22T14:35:02+00:00

Before I reinvent the wheel… This is just an EXAMPLE for describing the problem

  • 0

Before I reinvent the wheel…

This is just an EXAMPLE for describing the problem — let’s say you have a backend with collection of some data, and frontend which displays one item of the collection.

At the backend I have ItemIndex — whenever it changes, it fires up OnScroll event.

I also have AddNewItem method, it adds new item at the end of the collection. The end of the method is calling OnNewItem event handler.

And here is the catch — in AddNewItem I have to change ItemIndex, which fires OnScroll. One of the receivers of both (!) OnScroll and OnNewItem if frontend which displays selected item.

In such case it is called twice (not good). One solution would be altering item_index instead of ItemIndex, and this way preventing OnScroll, but I don’t like it because ItemIndex does not act as black box anymore.

Is there any established pattern for sequential firing events, and sending only “important” ones (here: OnNewItem overrides OnScroll)? My idea would be to define an event scope, then instead of sending events directly, just register them for sending, and at the close of scope sort them and send the required ones.

In general — question — how should I deal with potential sequential event triggering. Use internals to avoid sending redundant events? Ignore the overhead? …?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:35:03+00:00Added an answer on May 22, 2026 at 2:35 pm

    The answer seems obvious to me athough I could have easily missed something:

    private bool IsAdding { get; set; }
    private int item_index;
    private IList m_collection;
    
    public void AddNewItem(object item)
    {
        if (item == null)
        {
            throw new Exception("Cannot add null item."); // little bit of contracting never hurts
        }
    
        m_collection.Add(item);
        IsAdding = true;
        ItemIndex = collection.Count - 1; //I'm just making assumptions about this piece but it is not important how you decide what your index is to answer the question
    
        if (OnNewItem != null)
        {
           OnNewItem(this, EventArgs.Empty); 
        }
    }
    
    public int ItemIndex
    {
       get { return item_index =; }
       set
       {
           item_index = value;
           if (!IsAdding && OnScroll != null) //won't double fire event thanks to IsAdding
           {
               OnScroll(this, EventArgs.Empty);
           }
           IsAdding = false; //need to reset it
       }
    }
    

    One thing I would note is that you made mention of just simply altering item_index directly but that wouldn’t have a blackbox behavior. Well black box is all well and good … but that term only applies to objects interacting with this class we have been discussing.

    You should feel empowered to use the internals of your class within itself. It is not good OOP to blackbox items within itself. If you are doing that then your class probably has design issues where it should be split into multiple classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before you answer this I have never developed anything popular enough to attain high
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
Before I attempt to reinvent the wheel (via jQuery plugin or similar), I'm trying
We have just started our new assignment - web-based project. Before I get directly
Before I re-invent this particular wheel, has anybody got a nice routine for calculating
Before I reinvent the wheel, ASP.Net MVC 3 Tools Update includes an Internet Application
Before I reinvent the wheel - I want to be able to insert debugging
Before I start, I know there is this post and it doesn't answer my
Before I do this I figured I would ask if it was the best
Before, I have found the Cost in the execution plan to be a good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.