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

  • Home
  • SEARCH
  • 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 9182851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:39:40+00:00 2026-06-17T18:39:40+00:00

In C#, classes and interfaces can have event s: public class Foo { public

  • 0

In C#, classes and interfaces can have events:

public class Foo
{
    public event Action SomethingHappened;

    public void DoSomething()
    {
        // yes, i'm aware of the potential NRE
        this.SomethingHappened();
    }
}

This facilitates a push-based notification with minimal boilerplate code, and enables a multiple-subscriber model so that many observers can listen to the event:

var foo = new Foo();
foo.SomethingHappened += () => Console.WriteLine("Yay!");
foo.DoSomething();  // "Yay!" appears on console. 

Is there an equivalent idiom in Scala? What I’m looking for is:

  1. Minimal boilerplate code
  2. Single publisher, multiple subscribers
  3. Attach/detach subscribers

Examples of its use in Scala documentation would be wonderful. I’m not looking for an implementation of C# events in Scala. Rather, I’m looking for the equivalent idiom in Scala.

  • 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-17T18:39:42+00:00Added an answer on June 17, 2026 at 6:39 pm

    Idiomatic way for scala is not to use observer pattern.
    See Deprecating the Observer Pattern.

    Take a look at this answer for implementation.

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

Sidebar

Related Questions

I have a class that instantiates two classes which implement interfaces. I want one
Suppose I have a definition for a door: class Door { public void Lock()
Error: 'WithEvents' variables can only be typed as classes, interfaces or type parameters with
Given the following classes and interfaces class A{ @NotNull(groups=Section1.class) private String myString } interface
I have written a set of classes and interfaces that are implemented in Moose
I am trying to implement my persitent classes using interfaces. I have created the
I have extracted some of my concrete classes into interfaces I used to have
Why does C++ have public members that anyone can call and friend declarations that
I have an interface called IDataIO: public interface IDataIO { event DataReceivedEvent DataReceived; //.....more
I have two different classes that have the same class as a private field.

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.