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 8049873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:54:27+00:00 2026-06-05T06:54:27+00:00

Let’s say there is a buttonView ( ie. a simple button) . To register

  • 0

Let’s say there is a buttonView ( ie. a simple button) . To register a click in my rootView , i do as follows :

generally followed 1st Approach :
class RootView
{
var buttonView:ButtonView ;
….
buttonView.addEventListener( ButtonView.CLICK, buttonView_click ) ;
…
}

I wonder, why not a basic approach ( 2nd Approach ) is followed like this :

class RootView 
{
   var buttonView:ButtonView ; 
   buttonView.setFunction( buttonView_click ) ;

}


class ButtonView()
{
    public function setFunction(  someFunction:Function)
    {
        viewFunctionArray_Arr.push( someFunction ) 
    }

    public function onClick()
    {
        // remove dispatchEvent from here , instead 

        for ( var i=0; i< viewFunctionArray_Arr.length; i++)
        {
            //calling the registered functions of all the views one by one
            viewFunctionArray_Arr[i] ( ) ; 
        }

    }


}

If the explanation is regarding “Loose Coupling”, then i wonder, how “1st approach” is loose coupling, because afterall in the 1st approach, we are using instance “buttonView” in the views that need it. So rootView needs to know about buttonView. Isn’t it ?

  • 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-06-05T06:54:29+00:00Added an answer on June 5, 2026 at 6:54 am

    When you use addEventListener() Flash player is doing something very similar to your second approach.

    One reason I would use addEventListener() instead of passing a reference to a function is to avoid potential memory leaks:

    addEventListener() has some optional parameters. The last one specifies to use a weak reference: addEventListener(MouseEvent.CLICK, eventHandler, false, 0, true). Weak references do not prevent an object from getting garbage collected.

    There are cases when an object is disposed that you need to clean up things (ie: remove event listeners), and using a weak reference can mitigate some of the clean up tasks.

    In regards to loose coupling, I think both approaches are the same. In one case the parent object needs to know that the child view dispatches an event. In the other, the parent needs to know that it should pass an event handling function to the view. These are both loosely coupled in my opinion, there is nothing stopping you from using the child view somewhere else.

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

Sidebar

Related Questions

Let's say there is a graph and some set of functions like: create-node ::
Let's say that I have a date in R and it's formatted as follows.
let's say I have a select list as follows: <select name='languages'> <option value='german'>German</option> <option
Let's say I have a bunch of links that share a click event: <a
Let's say you create a wizard in an HTML form. One button goes back,
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let’s say I have a number like 0x448 . In binary this is 0100
Let's say I have a 12-bit Analog to Digital Converter (4096 bins). And let's
Let's say I have a structure named vertex with a method that adds two

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.