Parv Sharma
Parv Sharma

Reputation: 12705

Actor Pattern (Akka.Net) - Actors should be Constants OR Dynamic

Im confused between deciding what you use for my actors. Lets say iam building a Employee Management system in which there are
1.Multiple employees.
2.Each of one is supposed come to work every day.
3.Will mark his attendance and
4.Then will be allotted tasks

The problem im facing is what should be an actor in my case

Option 1 -
I Make a EmployeesActor(Note 's') - which will accept messages like EmployeePresentMessage containing EmployeeId (Information of which employee has marked attendance) and then will update the employee system's state.

Option 2 -
I Make a EmployeeActor class which will make 10 instances of itself (Depending upon the Total No of Employees in the Organization). So Now the messages like EmployeePresentMessage WIll be delivered to the specific Instance / Object of the EmployeeActor class Which will update its state.

Upvotes: 0

Views: 161

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35124

Actor is a special type of object, so you model your actors in a way that is similar to usual object-oriented modeling.

Actor is a single-threaded message handler with some state. You might design your actors based on what kind of state it needs.

Option 2 is the natural default where the state of each actor will be based on the messages to specific employee.

Option 1 could be useful in case you need to do some aggregation across multiple employees.

You are free to mix-and-match both approaches in different types of actors, e.g. have an instance of Employee actor type for each employee and have a single instance of Timetable actor type per department.

Upvotes: 3

Related Questions