I've seen it mentioned in several places in contexts like Erlang actor model, Groovy actors, Scala actor model etc. What does this refer to?
The actor model is a computer science concept that uses "actors" as the fundamental agents of computing. Actors take input, send output and perform functions. They can also create other actors.
Instead of calling methods, actors send messages to each other. Sending a message does not transfer the thread of execution from the sender to the destination. An actor can send a message and continue without blocking. It can, therefore, do more work, send and receive messages.
The actor model abstraction allows you to think about your code in terms of communication, not unlike the exchanges that occur between people in a large organization. Use of actors allows us to: Enforce encapsulation without resorting to locks.
The actor model is a conceptual model to deal with concurrent computation. It defines some general rules for how the system's components should behave and interact with each other. The most famous language that uses this model is probably Erlang .
I think Wikipedia sums it up best:
The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages, but differs in that object-oriented software is typically executed sequentially, while the Actor model is inherently concurrent. [snip] The Actor model is about the semantics of message passing.
Some time ago I wrote this blog post that explains the basic concepts of the model and builds a basic implementation with JavaScript. From the post:
In the Actor Model, an actor is the foundation on which you build the structure of your application, it has internal state invisible to the outer world and interacts with other actors through asynchronous messages.
If this sounds to you a lot like Object-Oriented Programming (OOP), you are right. The Actor Model can be thought as OOP with special treatment to messages: they are delivered asynchronously and executed synchronously by the receiver.
Every actor is identified with a unique address by which you send messages to it. When a message is processed, it is matched against the current behavior of the actor; which is nothing more than a function that defines the actions to be taken in reaction to the message. In response to a message, an actor may:
- Create more actors.
- Send messages to other actors.
- Designate internal state to handle the next message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With